From 5cea189b1b881d44413152349ec27425f10bdb3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Thu, 5 Feb 2015 00:26:38 +0000 Subject: [PATCH] Make thumb.php respond with HTTP 400 (not 500) on invalid parameters Bug: T88412 Change-Id: I21d34a3fb52992e51122ab7c07a38e946a55c680 --- thumb.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/thumb.php b/thumb.php index 7352dc4c5b..ebcf79f743 100644 --- a/thumb.php +++ b/thumb.php @@ -321,6 +321,7 @@ function wfStreamThumb( array $params ) { // Check for thumbnail generation errors... $msg = wfMessage( 'thumbnail_error' ); + $errorCode = 500; if ( !$thumb ) { $errorMsg = $errorMsg ?: $msg->rawParams( 'File::transform() returned false' )->escaped(); } elseif ( $thumb->isError() ) { @@ -330,10 +331,11 @@ function wfStreamThumb( array $params ) { } elseif ( $thumb->fileIsSource() ) { $errorMsg = $msg-> rawParams( 'Image was not scaled, is the requested width bigger than the source?' )->escaped(); + $errorCode = 400; } if ( $errorMsg !== false ) { - wfThumbError( 500, $errorMsg ); + wfThumbError( $errorCode, $errorMsg ); } else { // Stream the file if there were no errors $thumb->streamFile( $headers ); @@ -605,7 +607,9 @@ function wfThumbError( $status, $msg ) { header( 'Cache-Control: no-cache' ); header( 'Content-Type: text/html; charset=utf-8' ); - if ( $status == 404 ) { + if ( $status == 400 ) { + header( 'HTTP/1.1 400 Bad request' ); + } elseif ( $status == 404 ) { header( 'HTTP/1.1 404 Not found' ); } elseif ( $status == 403 ) { header( 'HTTP/1.1 403 Forbidden' ); -- 2.20.1