Skip to content

Fix reading overly large files - #954

Open
Leonard Hecker (lhecker) wants to merge 1 commit into
mainfrom
dev/lhecker/read-large-file-fix
Open

Leonard Hecker (lhecker) wants to merge 1 commit into
mainfrom
dev/lhecker/read-large-file-fix

Conversation

@lhecker

Copy link
Copy Markdown
Member

No description provided.


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);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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!

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.

1 participant