Skip to content
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

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

Andrews54757
Copy link
Contributor

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.

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) {
Copy link
Owner

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

Suggested change
if (n_segments > 0) {
for (int i = n_segments - 1; i < n_segments && n_segments > 0; ++i) {

Copy link
Contributor Author

@Andrews54757 Andrews54757 Feb 25, 2024

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that 👍

@ggerganov ggerganov merged commit 0d8fd84 into ggerganov:master Feb 26, 2024
@Andrews54757 Andrews54757 deleted the patch-1 branch February 26, 2024 16:50
jiahansu pushed a commit to WiseSync/whisper.cpp that referenced this pull request Apr 17, 2024
)

No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
viktor-silakov pushed a commit to viktor-silakov/whisper_node_mic.cpp that referenced this pull request May 11, 2024
)

No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
iThalay pushed a commit to iThalay/whisper.cpp that referenced this pull request Sep 23, 2024
)

No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
iThalay pushed a commit to iThalay/whisper.cpp that referenced this pull request Sep 23, 2024
)

No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
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.

2 participants