Skip to content

common : fix ngram cache draft out of bounds read - #31161

Open
ashokram-si wants to merge 1 commit into
ggml-org:masterfrom
ashokram-si:ngram-cache-short-input
Open

ashokram-si wants to merge 1 commit into
ggml-org:masterfrom
ashokram-si:ngram-cache-short-input

Conversation

@ashokram-si

Copy link
Copy Markdown

Overview

Fixes #30724

When input size is less than the ngram size, the start index becomes negative. Because the type is unsigned, it wraps around and causes a heap buffer overflow when reading the draft buffer.

Adds a simple bounds check to break early when the ngram size exceeds available tokens.

Additional information

Tested locally. The new test-ngram-cache fails on the old code when built with ASan/UBSan, and passes after the fix.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - reproduction, fix, and regression test were drafted with Claude Code; I reviewed and verified everything myself.

When input size is less than the ngram size, the start index becomes negative. Because the type is unsigned, it wraps around and causes a heap buffer overflow when reading the draft buffer.

Adds a simple bounds check to break early when the ngram size exceeds available tokens.

Fixes ggml-org#30724
@ashokram-si
ashokram-si requested review from a team and ggerganov as code owners October 25, 2026 19:15
@github-actions github-actions Bot added the testing Everything test related label Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: ngram-cache drafting reads before the start of draft for inputs shorter than 4 tokens

1 participant