Skip to content

Commit 4ca49d1

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

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
@@ -367,7 +367,9 @@ Jpeg2000Input::ojph_read_image()
367367
int ch = m_spec.nchannels;
368368
ojph::param_siz siz = codestream.access_siz();
369369

370-
const int bufsize = w * h * ch * buffer_bpp;
370+
const size_t bufsize
371+
= clamped_mult64(clamped_mult64(uint64_t(w), uint64_t(h)),
372+
clamped_mult64(uint64_t(ch), uint64_t(buffer_bpp)));
371373
m_buf.resize(bufsize);
372374
codestream.create();
373375

@@ -598,6 +600,14 @@ Jpeg2000Input::open(const std::string& name, ImageSpec& p_spec)
598600
m_spec.full_width = m_image->x1;
599601
m_spec.full_height = m_image->y1;
600602

603+
// Validation of resolution
604+
if (!check_open(m_spec,
605+
{ 0, std::numeric_limits<int>::max(), 0,
606+
std::numeric_limits<int>::max(), 0, 1, 0, 16384 })) {
607+
close();
608+
return false;
609+
}
610+
601611
m_spec.attribute("oiio:BitsPerSample", maxPrecision);
602612
m_spec.set_colorspace("sRGB");
603613

0 commit comments

Comments
 (0)