whisper : guard null source in buffer loader read callback - #3982
Open
ousamabenyounes wants to merge 1 commit into
Open
whisper : guard null source in buffer loader read callback#3982ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
whisper_init_from_buffer_with_params_no_state installs a read callback that copies from buf->buffer + current_offset. When the buffer is exhausted (or the supplied buffer is empty), size_to_copy is 0 and the source pointer can be null; passing a null pointer to memcpy is undefined behavior even for a zero-length copy (UBSan: 'null pointer passed as argument 2' at the memcpy). Loading a crafted/short model through the buffer loader could hit this. Skip the memcpy when there is nothing to copy. Loading from a null/empty or truncated buffer now fails gracefully (returns NULL) with no UB. This addresses bug 1 of ggml-org#3879. Bug 2 (integer overflow when sizing the mel filter buffer) is covered by the open PR ggml-org#3780.
ousamabenyounes
force-pushed
the
fix/issue-3879
branch
from
August 16, 2026 16:51
890b1d3 to
6c6e74c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The buffer-based model loader (
whisper_init_from_buffer_with_params) installs areadcallback that copies frombuf->buffer + current_offsetwithmemcpy.When the buffer is exhausted — or the supplied buffer is empty/NULL —
size_to_copyis 0 and the source pointer is NULL. Passing a NULL pointer tomemcpyis undefined behavior even for a zero-length copy.Skip the copy when there is nothing to copy.
This addresses bug 1 of #3879 (the null-pointer-to-
memcpyUB). Bug 2 (theint32overflow when sizing the mel-filter buffer) is a distinct issue alreadycovered by the open PR #3780, so it is intentionally left out here.
Why
Loading a crafted/short model through the buffer loader (e.g. via
whisper_init_from_buffer) drives the callback with nothing left to copy.UBSan flags the
memcpydirectly.Test verification (RED → GREEN)
Added
tests/test-whisper-buffer-loader.cpp: loading from a NULL/empty bufferand from a truncated non-model buffer must return
NULLwithout UB. It islabelled
ghso CI'sctest -L ghruns it.The undefined behavior is deterministic under UBSan (built with
-fsanitize=address,undefined -fno-sanitize-recover=all):RED (upstream base —
memcpyunguarded, new test applied):GREEN (with the fix):
Normal-build run (regression guard): the new test plus the existing
whisper-clitiny test and the UTF-8 unit test all pass.
Refs #3879 (bug 1). Bug 2 is tracked by #3780.