Skip to content

Reader: fix fill when implementation writes to reader directly #24677

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

Closed
wants to merge 1 commit into from

Conversation

gooncreeper
Copy link
Contributor

@gooncreeper gooncreeper commented Aug 3, 2025

r.end += stream is the same as r.end = r.end + stream, which causes r.end to be analyzed before stream is called and that value is added to. However, the implementation is allowed to write directly to r (for example, inflate does this to keep a window) and update r.end independently, causing the outdated value to be added to.

Progress towards #24695 (fixes the first two issues)

@alexrp alexrp requested a review from andrewrk August 3, 2025 15:36
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

Thanks!

`r.end += stream` is the same as `r.end = r.end + stream`, which causes
`r.end` to be analyzed before stream is called and that value is added
to. However, the implementation is allowed to write directly to `r` (for
example, inflate does this to keep a window) and update `r.end`
independently, causing the outdated value to be added to.
@andrewrk
Copy link
Member

andrewrk commented Aug 5, 2025

better fix: #24706

@andrewrk andrewrk closed this Aug 5, 2025
.stream = struct {
fn stream(r: *Reader, _: *Writer, _: Limit) StreamError!usize {
@memset(r.buffer[r.seek..], 0xff);
r.end = r.buffer.len;
Copy link
Member

Choose a reason for hiding this comment

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

actually this is not a valid use of the API

Copy link
Contributor Author

@gooncreeper gooncreeper Aug 10, 2025

Choose a reason for hiding this comment

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

@andrewrk Apologies, though what is invalid with it? The vtable doc comment says you can do this and flate.Decompress.streamIndirectInner takes advantage of this.

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.

3 participants