Skip to content

Commit ea4444d

Browse files
committed
fix(iv): avoid crash with OpenGL + multi-channel images (AcademySoftwareFoundation#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 <[email protected]>
1 parent 60690d0 commit ea4444d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/iv/ivgl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,10 @@ IvGL::load_texture(int x, int y, int width, int height)
14941494
}
14951495

14961496
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo_objects[m_last_pbo_used]);
1497-
glBufferData(GL_PIXEL_UNPACK_BUFFER, width * height * spec.pixel_bytes(),
1497+
glBufferData(GL_PIXEL_UNPACK_BUFFER,
1498+
GLsizeiptr(uint64_t(width) * uint64_t(height)
1499+
* uint64_t(nchannels)
1500+
* uint64_t(spec.format.size())),
14981501
&m_tex_buffer[0], GL_STREAM_DRAW);
14991502
GLERRPRINT("After buffer data");
15001503
m_last_pbo_used = (m_last_pbo_used + 1) & 1;

0 commit comments

Comments
 (0)