Fix reading overly large files - #954
Open
Leonard Hecker (lhecker) wants to merge 1 commit into
Open
Leonard Hecker (lhecker) wants to merge 1 commit into
Leonard Hecker (lhecker) wants to merge 1 commit into
Conversation
Leonard Hecker (lhecker)
requested a review
from Dustin L. Howett (DHowett)
September 16, 2026 23:22
|
|
||
| let gap_len_old = self.gap_len; | ||
| let gap_len_new = (len + gap_chunk + gap_chunk - 1) & !(gap_chunk - 1); | ||
| let gap_len_new = gap_len_new.min(self.reserve - self.text_length); |
Member
Author
There was a problem hiding this comment.
Without this change (and the removed if condition below), reading files larger than the max. memory would read in chunks of 4KiB.
Comment on lines
+856
to
+864
| // Get the length of the file. 0 = not a file. | ||
| let file_len = if done { | ||
| // But if the first 4KiB read already contains the entire file, we won't need | ||
| // the file length below (we early return). The value here doesn't matter. | ||
| 0 | ||
| } else { | ||
| // We can't acquire the length on pipes, for instance. | ||
| file.metadata().ok().and_then(|m| m.len().try_into().ok()).unwrap_or(0) | ||
| }; |
Member
Author
There was a problem hiding this comment.
And this and the changes below prevent that we ever (typically) run into these out of memory situations in the first place.
It fixes the issue from both sides!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.