From a9c937da33f04516ba50f8457452e99a2bdf1784 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Wed, 27 Dec 2023 12:27:34 -0800 Subject: [PATCH] fix(iv): avoid crash with OpenGL + multi-channel images (#4087) For image with more than 4 channels, we were misallocating the OpenGL buffer by using the total channels instead of the 4 we wanted to create the texture out of. Also, make sure the calculation usees wide types to avoid possible integer overflow. Signed-off-by: Larry Gritz --- src/iv/ivgl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/iv/ivgl.cpp b/src/iv/ivgl.cpp index af9beef4d8..de923e7076 100644 --- a/src/iv/ivgl.cpp +++ b/src/iv/ivgl.cpp @@ -1536,7 +1536,10 @@ IvGL::load_texture(int x, int y, int width, int height) } glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo_objects[m_last_pbo_used]); - glBufferData(GL_PIXEL_UNPACK_BUFFER, width * height * spec.pixel_bytes(), + glBufferData(GL_PIXEL_UNPACK_BUFFER, + GLsizeiptr(uint64_t(width) * uint64_t(height) + * uint64_t(nchannels) + * uint64_t(spec.format.size())), &m_tex_buffer[0], GL_STREAM_DRAW); print_error("After buffer data"); m_last_pbo_used = (m_last_pbo_used + 1) & 1;