Skip to content

Exif crash on unknown encoding was fixed #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests added
Comments added
All bugs with zend_multibyte_encoding_converter was fixed in exif.
  • Loading branch information
Draal committed Mar 5, 2013
commit 921df43e57fd954447cb0eadc108f21a7d208cb0
10 changes: 6 additions & 4 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2643,14 +2643,15 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
} else {
decode = ImageInfo->decode_unicode_le;
}
/* XXX this will fail again if encoding_converter delivers a real length and doesn't fill len */
if (zend_multibyte_encoding_converter(
(unsigned char**)pszInfoPtr,
&len,
(unsigned char*)szValuePtr,
ByteCount,
zend_multibyte_fetch_encoding(ImageInfo->encode_unicode TSRMLS_CC),
zend_multibyte_fetch_encoding(decode TSRMLS_CC)
TSRMLS_CC) < 0) {
TSRMLS_CC) == (size_t)-1) {
len = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
}
return len;
Expand All @@ -2663,14 +2664,15 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
*pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8;
ByteCount -= 8;
/* XXX this will fail again if encoding_converter delivers a real length and doesn't fill len */
if (zend_multibyte_encoding_converter(
(unsigned char**)pszInfoPtr,
&len,
(unsigned char*)szValuePtr,
ByteCount,
zend_multibyte_fetch_encoding(ImageInfo->encode_jis TSRMLS_CC),
zend_multibyte_fetch_encoding(ImageInfo->motorola_intel ? ImageInfo->decode_jis_be : ImageInfo->decode_jis_le TSRMLS_CC)
TSRMLS_CC) < 0) {
TSRMLS_CC) == (size_t)-1) {
len = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
}
return len;
Expand Down Expand Up @@ -2700,8 +2702,8 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_field, int tag, char *szValuePtr, int ByteCount TSRMLS_DC)
{
xp_field->tag = tag;

/* Copy the comment */
/* XXX this will fail again if encoding_converter delivers a real length and doesn't fill len */
if (zend_multibyte_encoding_converter(
(unsigned char**)&xp_field->value,
&xp_field->size,
Expand Down
Binary file added ext/exif/tests/exif_encoding_crash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions ext/exif/tests/exif_encoding_crash.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
PHP crash when zend_multibyte_encoding_converter returns (size_t)-1)
--SKIPIF--
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
--FILE--
<?php
$infile = dirname(__FILE__).'/exif_encoding_crash.jpg';
var_dump(exif_read_data($infile));
?>
===DONE===
--EXPECTF--
Warning: exif_read_data(exif_encoding_crash.jpg): Process tag(x9003=DateTimeOri): Illegal pointer offset(%s) in %s on line %d

Warning: exif_read_data(exif_encoding_crash.jpg): Error reading from file: got=x%x(=%d) != itemlen-%d=x%x(=%d) in %s on line %d

Warning: exif_read_data(exif_encoding_crash.jpg): Invalid JPEG file in %s on line %d
bool(false)
===DONE===