php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54518 filesize and reafile incosistencies with pdf file
Submitted: 2011-04-12 21:55 UTC Modified: 2011-04-13 15:16 UTC
From: gabriel at justbull dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.3.6 OS: Centos 5.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gabriel at justbull dot com
New email:
PHP Version: OS:

 

 [2011-04-12 21:55 UTC] gabriel at justbull dot com
Description:
------------
With some PDF files (not all), the filesize function report a file size that is 
not representative of the size of the file produced by readfile.

The filesize gives the same filesize as the original file. But the readfile 
doesn't give the exact same content as the original file, making it slightly 
bigger.

This results in some part of the file being cut if you include the filesize in the 
header.

I can reproduce this bug on 2 servers,

Test script:
---------------
header('Content-Type: application/pdf');
header("Content-Length: ".filesize($file));
readfile($file);
exit();

// THIS CODE PRODUCE THE SAME PROBLEM 

ob_start();
readfile($file);
$output = ob_get_clean();
header('Content-Type: application/pdf');
header("Content-Length: ".strlen($output));
echo $output;
exit();

Expected result:
----------------
Expect the filesize to return the right filesize. Or the readfile to output the 
exactly same content as the original file. 

Actual result:
--------------
The filesize function report a file size that is not representative of the size of 
the file produced by readfile.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-13 10:44 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2011-04-13 10:44 UTC] cataphract@php.net
Almost certainly bogus, but in any case, what is this extra data that's causing the discrepancy? What's its place in the output stream?

Most likely there's whitespace or a BOM mark in the script (or an included script).
 [2011-04-13 15:14 UTC] gabriel at justbull dot com
Ok, an included file had line returns after the ?>. I guess what threw me in the 
wrong direction is that it was still working fine with some PDFs.
 [2011-04-13 15:14 UTC] gabriel at justbull dot com
-Status: Feedback +Status: Closed
 [2011-04-13 15:14 UTC] gabriel at justbull dot com
Closing
 [2011-04-13 15:16 UTC] pajoye@php.net
-Status: Closed +Status: Bogus
 [2011-04-13 15:16 UTC] pajoye@php.net
Not a php bug > bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC