Skip to content

Commit

Permalink
fix(iv): avoid crash with OpenGL + multi-channel images (AcademySoftw…
Browse files Browse the repository at this point in the history
…areFoundation#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]>
Signed-off-by: Peter Kovář <[email protected]>
  • Loading branch information
lgritz authored and 1div0 committed Feb 24, 2024
1 parent 27e898e commit 2226201
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/iv/ivgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2226201

Please sign in to comment.