Skip to content

whisper : fix int overflow in whisper_full_parallel chunk offsets - #4044

Merged
danbev merged 1 commit into
ggml-org:masterfrom
kmadiar:fix-parallel-offset-overflow
Sep 15, 2026
Merged

danbev merged 1 commit into
ggml-org:masterfrom
kmadiar:fix-parallel-offset-overflow

Conversation

@kmadiar

@kmadiar kmadiar commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #4039.

whisper_full_parallel() computed the per-chunk time offset as 100 * ((i + 1) * n_samples_per_processor) / WHISPER_SAMPLE_RATE in int before adding it to the int64_t offset_t. For chunk boundaries later than ~22 min at 16 kHz (100 * samples > INT_MAX) the multiplication overflows, corrupting the merged segment t0/t1 and the split times printed in the log.

This PR computes the offset once per chunk in int64_t (100LL * ...) and reuses it for both the segment merge and the split-time log.

Verification — 46 min file (samples/jfk.wav looped), --processors 2, boundary at 23:00:

Before, built with -fsanitize=undefined:

src/whisper.cpp:7980:30: runtime error: signed integer overflow: 100 * 22080000 cannot be represented in type 'int'
src/whisper.cpp:7981:30: runtime error: signed integer overflow: 100 * 22080000 cannot be represented in type 'int'
src/whisper.cpp:8023:9:  runtime error: signed integer overflow: 100 * 22080000 cannot be represented in type 'int'
whisper_full_parallel: split 1 - 00:-21:-44.-350

After: no overflow reports, split 1 - 00:23:00.000, all segment offsets in the JSON output non-negative and monotonic. --processors 4 (Release) reports splits at 00:11:30 / 00:23:00 / 00:34:30.

Note: on Apple clang Release builds the UB happens to yield the correct value, which is why this is mostly seen on MSVC/Windows (as in the issue); the UBSan build reproduces it on macOS.

I have a small regression test (whisper_full_parallel on a 45 min silent buffer with duration_ms = 1000, checking the logged split time via whisper_log_set; ~3 s, fails on master with 00:-22:-14.-350). Happy to add it to this PR or a follow-up if you'd like it.

Token-level timestamps in parallel mode (#2036, #3726) are a separate issue and unchanged here.

@danbev
danbev merged commit da54572 into ggml-org:master Sep 15, 2026
43 of 47 checks passed
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.

whisper_full_parallel: signed 32-bit overflow corrupts segment timestamps for long audio

2 participants