From 7eef9d941e69705ea05f9037bc0740f96f0ce0ba Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Tue, 3 Feb 2015 16:33:48 -0500 Subject: [PATCH] Recommitting filesize checks in smartReadFile --- .../application/controllers/ApiController.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 07d075267..124b4b4d0 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -157,9 +157,17 @@ class ApiController extends Zend_Controller_Action if (!$location || $location == "") { throw new FileDoesNotExistException("Requested file does not exist!"); } - - $size= filesize($location); - + + // If we're passing in a Stored File object, it's faster + // to use getFileSize() and pass in the result + if (!$size || $size <= 0) { + $size= filesize($location); + } + + if ($size <= 0) { + throw new Exception("Invalid file size returned for file at $location"); + } + $fm = @fopen($location, 'rb'); if (!$fm) { header ("HTTP/1.1 505 Internal server error");