From 973c5fa1ec80bdfdcff56d4ca3109ec51c2306e4 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Fri, 17 Jan 2003 18:51:30 +0000 Subject: [PATCH] fix jp2 detection and add testfile --- ext/standard/image.c | 15 ++++++--------- .../tests/image/image_type_to_mime_type.phpt | 4 +++- ext/standard/tests/image/test1pix.jp2 | Bin 0 -> 243 bytes 3 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 ext/standard/tests/image/test1pix.jp2 diff --git a/ext/standard/image.c b/ext/standard/image.c index b19de960ca..2b06e0ed39 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -623,7 +623,7 @@ static struct gfxinfo *php_handle_jpc(php_stream * stream TSRMLS_DC) result->channels = php_read2(stream TSRMLS_CC); /* Csiz */ - /* Collect and average bit depth info */ + /* Collect bit depth info */ highest_bit_depth = bit_depth = 0; for (i = 0; i < result->channels; i++) { bit_depth = php_stream_getc(stream); /* Ssiz[i] */ @@ -665,11 +665,7 @@ static struct gfxinfo *php_handle_jp2(php_stream *stream TSRMLS_DC) box_length = php_read4(stream TSRMLS_CC); /* LBox */ /* TBox */ if (php_stream_read(stream, (void *)&box_type, sizeof(box_type)) != sizeof(box_type)) { - break; - } - - /* Safe to use the 0 return for EOF as neither of these can be 0 */ - if (box_length == 0 || box_type == 0) { + /* Use this as a general "out of stream" error */ break; } @@ -1073,9 +1069,6 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC) if (!memcmp(filetype, php_sig_iff, 4)) { return IMAGE_FILETYPE_IFF; } - if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) { - return IMAGE_FILETYPE_WBMP; - } if (php_stream_read(stream, filetype+4, 8) != 8) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read error!"); @@ -1086,6 +1079,10 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC) return IMAGE_FILETYPE_JP2; } +/* AFTER ALL ABOVE FAILED */ + if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) { + return IMAGE_FILETYPE_WBMP; + } return IMAGE_FILETYPE_UNKNOWN; } /* }}} */ diff --git a/ext/standard/tests/image/image_type_to_mime_type.phpt b/ext/standard/tests/image/image_type_to_mime_type.phpt index da882aae8d..94aabba0b9 100644 --- a/ext/standard/tests/image/image_type_to_mime_type.phpt +++ b/ext/standard/tests/image/image_type_to_mime_type.phpt @@ -25,9 +25,11 @@ image_type_to_mime_type() var_dump($result); ?> --EXPECT-- -array(10) { +array(11) { ["test1pix.bmp"]=> string(9) "image/bmp" + ["test1pix.jp2"]=> + string(9) "image/jp2" ["test1pix.jpc"]=> string(24) "application/octet-stream" ["test1pix.jpg"]=> diff --git a/ext/standard/tests/image/test1pix.jp2 b/ext/standard/tests/image/test1pix.jp2 new file mode 100644 index 0000000000000000000000000000000000000000..8a1172e10d96f5e0d8e43a0482fc3105fc373c7d GIT binary patch literal 243 zcmZQzVBpCLP*C9IYUg5LU=T?wsVvAUFj4@r8KAT-kj?;d#WFKeihwjD7&Ei8gBT3_ z$@w`&U>1V_h!0ep{NMk7AcH=L2UQGaV&OBhGcrQZ{~!h)ka9*=78VAE|1k{8O679p z4CM@EkMbGv8S);b`v74|05cG}hF=20#Q!Nk8yUS5vlCNFb&d55^vwTHU;uf7fkB0V R@&DxeA2?XL8_>c3n*bghGXDSo literal 0 HcmV?d00001 -- 2.50.1