Skip to content

Commit a9c937d

Browse files
authored
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 <[email protected]>
1 parent 6ed14ff commit a9c937d

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
@@ -1536,7 +1536,10 @@ IvGL::load_texture(int x, int y, int width, int height)
15361536
}
15371537

15381538
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo_objects[m_last_pbo_used]);
1539-
glBufferData(GL_PIXEL_UNPACK_BUFFER, width * height * spec.pixel_bytes(),
1539+
glBufferData(GL_PIXEL_UNPACK_BUFFER,
1540+
GLsizeiptr(uint64_t(width) * uint64_t(height)
1541+
* uint64_t(nchannels)
1542+
* uint64_t(spec.format.size())),
15401543
&m_tex_buffer[0], GL_STREAM_DRAW);
15411544
print_error("After buffer data");
15421545
m_last_pbo_used = (m_last_pbo_used + 1) & 1;

0 commit comments

Comments
 (0)