Skip to content

Commit 9a426ad

Browse files
committed
8318951: Additional negative value check in JPEG decoding
Reviewed-by: sgehwolf Backport-of: 75ce02fe74e1232bfa8d72b4fdad82ed938ef957
1 parent aa44346 commit 9a426ad

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,10 @@ imageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
11311131
return;
11321132
}
11331133
num_bytes += sb->remaining_skip;
1134+
// Check for overflow if remaining_skip value is too large
1135+
if (num_bytes < 0) {
1136+
return;
1137+
}
11341138
sb->remaining_skip = 0;
11351139

11361140
/* First the easy case where we are skipping <= the current contents. */

jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ sun_jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
406406
return;
407407
}
408408
num_bytes += src->remaining_skip;
409+
// Check for overflow if remaining_skip value is too large
410+
if (num_bytes < 0) {
411+
return;
412+
}
409413
src->remaining_skip = 0;
410414
ret = (int)src->pub.bytes_in_buffer; /* this conversion is safe, because capacity of the buffer is limited by jnit */
411415
if (ret >= num_bytes) {

0 commit comments

Comments
 (0)