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

core: advance reader's position if pattern cannot be found, fixes out of memory from #301 #344

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions symphonia-core/src/io/buf_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ impl<'a> BufReader<'a> {
// return the remainder of the buffer or scan_length bytes, which ever is shorter, we return
// that here.
if remaining < pattern.len() || scan_len < pattern.len() {
self.pos = end;
return Ok(&self.buf[start..end]);
}

let mut j = start;
let mut i = start + pattern.len();
let mut i = start;
Copy link
Owner

Choose a reason for hiding this comment

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

Why were these renamed? Usually the outer loop variable is i, and j is the inner loop. It adds noise the commit. Or am I missing something subtle?

Copy link
Author

Choose a reason for hiding this comment

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

sorry it was hard to read for me that i is greater than j.
I agree with your statement about outer and inner loop, but there is a single loop here and buf[j..i] looked too wierd for me.

np I can remove this, just confirm you want to remove noise.

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, if it's too weird to you then it's probably too weird to others as well. I merged it as is.

It was looking strange to me because there is a single loop, but j was being used in the loop condition instead of i.

let mut j = start + pattern.len();

while i < end {
if &self.buf[j..i] == pattern {
while j < end {
if &self.buf[i..j] == pattern {
break;
}
i += align;
j += align;
i += align;
}

self.pos = cmp::min(i, self.buf.len());
self.pos = cmp::min(j, self.buf.len());
Ok(&self.buf[start..self.pos])
}

Expand Down
Loading