Skip to content

Conversation

@cmb69
Copy link
Member

@cmb69 cmb69 commented Jun 22, 2018

Some JFIF images contain empty APP segments, i.e. those which consist
only of the marker bytes and the length, but without actual content.
It appears to be doubtful to have empty APP segments, but we should
apply the robustness principle, and accept these, instead of simply
failing in this case.

We choose to add empty APP segments to $imageinfo with an empty string
as value, instead of NULL, or even to omit these segments altogether.

This patch also fixes the potential issue that php_stream_read() might
not read the supposed number of bytes, which could result in garbage to
be added to the read value.

As far as I know, php_stream_read() returns the actual number of bytes read, and may read less bytes than requested. If so, checking the result for <= 0 would not be correct anyway. Please correct me if I'm wrong.

Regarding the decision to add an empty string instead of NULL: this is somewhat arbitrary, given that the meaning of empty APP segments is not clear, but it is the simplest fix, and is certainly not completely illogical.

Some JFIF images contain empty APP segments, i.e. those which consist
only of the marker bytes and the length, but without actual content.
It appears to be doubtful to have empty APP segments, but we should
apply the robustness principle, and accept these, instead of simply
failing in this case.

We choose to add empty APP segments to $imageinfo with an empty string
as value, instead of NULL, or even to omit these segments altogether.

This patch also fixes the potential issue that php_stream_read() might
not read the supposed number of bytes, which could result in garbage to
be added to the read value.
@krakjoe krakjoe added the Bug label Jun 25, 2018
@cmb69
Copy link
Member Author

cmb69 commented Jun 26, 2018

If nobody objects, I'm going to merge this PR during the weekend.

@php-pulls
Copy link

Comment on behalf of cmb at php.net:

Applied via ae04110 and merged up.

@php-pulls php-pulls closed this Jun 30, 2018
@cmb69 cmb69 deleted the getimagesize-empty-app branch January 21, 2019 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants