-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream.wasm: Fix invalid memory access when no segments are returned #1902
Conversation
No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
@@ -103,11 +103,11 @@ void stream_main(size_t index) { | |||
|
|||
{ | |||
const int n_segments = whisper_full_n_segments(ctx); | |||
for (int i = n_segments - 1; i < n_segments; ++i) { | |||
const char * text = whisper_full_get_segment_text(ctx, i); | |||
if (n_segments > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only process the last segment. We want to process all segments
if (n_segments > 0) { | |
for (int i = n_segments - 1; i < n_segments && n_segments > 0; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single_segment
is set to true so it will not output more than one segment. Furthermore, the original code's for
loop will only iterate once anyways. Because it starts from n-1
and stops at n-1
, it will only process the last segment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed that 👍
No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker. This causes an invalid memory access error as
whisper_full_get_segment_text(ctx, -1)
is called.