stb_vorbis: heap buffer overflow in comment header parsing (integer truncation in setup_malloc)
Author: AvAl4nchCreated Sep 20, 2026Updated Sep 20, 2026
setup_malloc takes its size as int, but callers compute it with sizeof, which is size_t. The product truncates at the call boundary:
static void *setup_malloc(vorb *f, int sz) /* int */
...
f->comment_list_length = get32_packet(f); /* from the file */
f->comment_list = (char**) setup_malloc(f, sizeof(char*) * (f->comment_list_length));
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
for(i=0; i < f->comment_list_length; ++i) {
f->comment_list[i] = (char*)setup_malloc(f, sizeof(char) * (len+1));With comment_list_length = 0x20000001:
8 * 0x20000001 = 0x1_0000_0008 -> truncated to int = 8malloc(8) succeeds so the NULL guard passes, then the loop writes 536,870,913 pointers into 8 bytes.
ASAN, 915-byte .ogg (comment header declaring that count, followed by 8 zero-length comments):
WRITE of size 8 at ... in start_decoder stb_vorbis.c:3670
0 bytes after 8-byte region, allocated at stb_vorbis.c:3664Same truncation is reachable at 3716, 3802, 3878 (three-way product), 3880 and 4049.
Fix: make setup_malloc and setup_temp_malloc take size_t and return NULL above INT_MAX. Bounding comment_list_length by the bytes left in the packet would also help, since each comment costs at least 4 bytes.
Found by fuzzing at 2c980bb.
Source: nothings/stb