8000 Fix UB in ogg_sync_pageseek before any data is buffered by StephaniePinkish · Pull Request #118 · xiph/ogg · GitHub
[go: up one dir, main page]

Skip to content

Fix UB in ogg_sync_pageseek before any data is buffered - #118

Open
StephaniePinkish wants to merge 1 commit into
xiph:mainfrom
StephaniePinkish:fix/pageseek-null-data
Open

StephaniePinkish wants to merge 1 commit into
xiph:mainfrom
StephaniePinkish:fix/pageseek-null-data

Conversation

@StephaniePinkish
Copy link
Copy Markdown

Until the first ogg_sync_buffer() call, oy->data is NULL, so ogg_sync_pageseek() computes oy->data+oy->returned on a null pointer. With -fsanitize=undefined, clang reports:

framing.c:649:16: runtime error: applying zero offset to null pointer
    #0 ogg_sync_pageseek framing.c:649
    #1 _get_next_page vorbisfile.c:115
    #2 _fetch_headers vorbisfile.c:290
    #3 _ov_open1 vorbisfile.c:914
    #4 ov_open_callbacks vorbisfile.c:995

libvorbis's vorbisfile calls this on every open, before it has fed any data, so any sanitized application that decodes Vorbis hits it. 7cf42ea moved this computation after ogg_sync_check(), but that check passes while data is still NULL.

Minimal reproduction:

ogg_sync_state oy;
ogg_page og;
ogg_sync_init(&oy);
ogg_sync_pageseek(&oy, &og);   /* UBSan: applying zero offset to null pointer */

The fix returns 0 ("need more data") when there is no buffer yet. That is what the function already returns for an empty buffer, so callers see no change. The commit adds a self-test for this case to test_framing.

oy->data is NULL until the first ogg_sync_buffer(), so return 0 (need
more data) instead of offsetting a null pointer.
@StephaniePinkish
StephaniePinkish changed the base branch from master to main November 13, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0