Skip to content

Commit

Permalink
8318951: Additional negative value check in JPEG decoding
Browse files Browse the repository at this point in the history
Reviewed-by: azvegint, prr
  • Loading branch information
jayathirthrao committed Oct 31, 2023
1 parent 328b381 commit 75ce02f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/java.desktop/share/native/libjavajpeg/imageioJPEG.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@ imageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
return;
}
num_bytes += sb->remaining_skip;
// Check for overflow if remaining_skip value is too large
if (num_bytes < 0) {
return;
}
sb->remaining_skip = 0;

/* First the easy case where we are skipping <= the current contents. */
Expand Down
4 changes: 4 additions & 0 deletions src/java.desktop/share/native/libjavajpeg/jpegdecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ sun_jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
return;
}
num_bytes += src->remaining_skip;
// Check for overflow if remaining_skip value is too large
if (num_bytes < 0) {
return;
}
src->remaining_skip = 0;
ret = (int)src->pub.bytes_in_buffer; /* this conversion is safe, because capacity of the buffer is limited by jnit */
if (ret >= num_bytes) {
Expand Down

0 comments on commit 75ce02f

Please sign in to comment.