File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -3509,7 +3509,7 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
3509
3509
return FALSE;
3510
3510
marker = c ;
3511
3511
length = php_jpg_get16 (data + pos );
3512
- if (pos + length >= ImageInfo -> Thumbnail .size ) {
3512
+ if (length > ImageInfo -> Thumbnail . size || pos >= ImageInfo -> Thumbnail .size - length ) {
3513
3513
return FALSE;
3514
3514
}
3515
3515
#ifdef EXIF_DEBUG
@@ -3530,6 +3530,10 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
3530
3530
case M_SOF14 :
3531
3531
case M_SOF15 :
3532
3532
/* handle SOFn block */
3533
+ if (length < 8 || ImageInfo -> Thumbnail .size - 8 < pos ) {
3534
+ /* exif_process_SOFn needs 8 bytes */
3535
+ return FALSE;
3536
+ }
3533
3537
exif_process_SOFn (data + pos , marker , & sof_info );
3534
3538
ImageInfo -> Thumbnail .height = sof_info .height ;
3535
3539
ImageInfo -> Thumbnail .width = sof_info .width ;
@@ -4177,7 +4181,9 @@ PHP_FUNCTION(exif_thumbnail)
4177
4181
ZVAL_STRINGL (return_value , ImageInfo .Thumbnail .data , ImageInfo .Thumbnail .size );
4178
4182
if (arg_c >= 3 ) {
4179
4183
if (!ImageInfo .Thumbnail .width || !ImageInfo .Thumbnail .height ) {
4180
- exif_scan_thumbnail (& ImageInfo );
4184
+ if (!exif_scan_thumbnail (& ImageInfo )) {
4185
+ ImageInfo .Thumbnail .width = ImageInfo .Thumbnail .height = 0 ;
4186
+ }
4181
4187
}
4182
4188
zval_dtor (p_width );
4183
4189
zval_dtor (p_height );
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug 77540 (Invalid Read on exif_process_SOFn)
3
+ --SKIPIF--
4
+ <?php if (!extension_loaded ('exif ' )) print 'skip exif extension not available ' ;?>
5
+ --FILE--
6
+ <?php
7
+ $ width = $ height = 42 ;
8
+ $ s = exif_thumbnail (__DIR__ ."/bug77540.jpg " , $ width , $ height );
9
+ echo "Width " .$ width ."\n" ;
10
+ echo "Height " .$ height ."\n" ;
11
+ ?>
12
+ DONE
13
+ --EXPECTF--
14
+ Width 0
15
+ Height 0
16
+ DONE
You can’t perform that action at this time.
0 commit comments