|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10166 read_exif_data loads whole image into memory
Submitted: 2001-04-04 13:48 UTC Modified: 2005-02-01 23:02 UTC
From: vvo at geocities dot com Assigned:
Status: Closed Package: EXIF related
PHP Version: 4.0 Latest CVS (04/04/2001) OS: Linux 2.2
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.
Block user comment
Status: Assign to:
Bug Type:
From: vvo at geocities dot com
New email:
PHP Version: OS:


 [2001-04-04 13:48 UTC] vvo at geocities dot com
Some users observed that read_exif_data is too slow with 1MB image files, which is a typical size for digital camera output. I looked into the implementation (ext/exif/exif.c) and it looks like the whole compressed image data is always read into memory, even though read_exif_data should be concerned with just the file header.

Here's a line from function read_exif_data:
	ret = php_read_jpeg_exif(&ImageInfo, (*p_name)->value.str.val,1);

The last parameter (ReadAll=1), causes the whole image data loaded into memory inside function scan_JPEG_header:

    if (ReadAll) {
        int cp, ep, size;
        /* Determine how much file is left. */
        cp = ftell(infile);
        fseek(infile, 0, SEEK_END);
        ep = ftell(infile);
        fseek(infile, cp, SEEK_SET);

        size = ep-cp;
        Data = (uchar *)malloc(size);
        if (Data == NULL) {
            php_error(E_ERROR,"could not allocate data for entire image");

        got = fread(Data, 1, size, infile);
        if (got != size) {
            php_error(E_ERROR,"could not read the rest of the image");

        Sections[*SectionsRead].Data = Data;
        Sections[*SectionsRead].Size = size;
        Sections[*SectionsRead].Type = PSEUDO_IMAGE_MARKER;
        *HaveAll = 1;
    return TRUE;

I believe the line above should be changed to feed 0 as value of parameter ReadAll.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-30 13:03 UTC]
In latest CVS there I have added an optional parameter
for read_exif_data():

proto read_exif_data(string filename [, int readall])

By setting 'readall' to 0 you can prevent it from
loading all of the file into memory.

Please test this.


PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 14:01:29 2024 UTC