Skip to content

Commit 5884219

Browse files
cfillionocornut
authored andcommitted
imgui_freetype: Assert if bitmap size exceed chunk size to avoid buffer overflow. (#5731)
1 parent f2a522d commit 5884219

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

misc/freetype/imgui_freetype.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
508508
// Allocate temporary rasterization data buffers.
509509
// We could not find a way to retrieve accurate glyph size without rendering them.
510510
// (e.g. slot->metrics->width not always matching bitmap->width, especially considering the Oblique transform)
511-
// We allocate in chunks of 256 KB to not waste too much extra memory ahead. Hopefully users of FreeType won't find the temporary allocations.
511+
// We allocate in chunks of 256 KB to not waste too much extra memory ahead. Hopefully users of FreeType won't mind the temporary allocations.
512512
const int BITMAP_BUFFERS_CHUNK_SIZE = 256 * 1024;
513513
int buf_bitmap_current_used_bytes = 0;
514514
ImVector<unsigned char*> buf_bitmap_buffers;
@@ -556,6 +556,7 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
556556
buf_bitmap_current_used_bytes = 0;
557557
buf_bitmap_buffers.push_back((unsigned char*)IM_ALLOC(BITMAP_BUFFERS_CHUNK_SIZE));
558558
}
559+
IM_ASSERT(buf_bitmap_current_used_bytes + bitmap_size_in_bytes <= BITMAP_BUFFERS_CHUNK_SIZE); // We could probably allocate custom-sized buffer instead.
559560

560561
// Blit rasterized pixels to our temporary buffer and keep a pointer to it.
561562
src_glyph.BitmapData = (unsigned int*)(buf_bitmap_buffers.back() + buf_bitmap_current_used_bytes);

0 commit comments

Comments
 (0)