Skip to content

Commit a9ebb3c

Browse files
committed
fix(jpeg2000): Watch out for int overflow in buffer size computation (AcademySoftwareFoundation#5143)
Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 061ed00 commit a9ebb3c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/jpeg2000.imageio/jpeg2000input.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ Jpeg2000Input::ojph_read_image()
392392
int ch = m_spec.nchannels;
393393
ojph::param_siz siz = codestream.access_siz();
394394

395-
const int bufsize = w * h * ch * buffer_bpp;
395+
const size_t bufsize
396+
= clamped_mult64(clamped_mult64(uint64_t(w), uint64_t(h)),
397+
clamped_mult64(uint64_t(ch), uint64_t(buffer_bpp)));
396398
m_buf.resize(bufsize);
397399
codestream.create();
398400

@@ -622,6 +624,14 @@ Jpeg2000Input::open(const std::string& name, ImageSpec& p_spec)
622624
m_spec.full_width = m_image->x1;
623625
m_spec.full_height = m_image->y1;
624626

627+
// Validation of resolution
628+
if (!check_open(m_spec,
629+
{ 0, std::numeric_limits<int>::max(), 0,
630+
std::numeric_limits<int>::max(), 0, 1, 0, 16384 })) {
631+
close();
632+
return false;
633+
}
634+
625635
m_spec.attribute("oiio:BitsPerSample", maxPrecision);
626636
m_spec.set_colorspace("srgb_rec709_scene");
627637

0 commit comments

Comments
 (0)