-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix high memory usage due to Deflater buffering
When support for ZipCrypto was added, an internal StringIO buffer was added to Deflater, in order to fix a decryption bug. While this worked, it caused unlimited memory growth when compressing large files. The proper fix is to writer the encryption header in init_next_entry instead of finalize_current_entry, so the headers are written before any encrypted data. Because of this fix we can remove the buffering in Deflater, which keeps memory usage low and allows to stream compressed data while it is written. This should fix issue #233.
- Loading branch information
1 parent
a3ca219
commit 7a4b8bb
Showing
2 changed files
with
7 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
7a4b8bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this fix!
7a4b8bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I just saw the linked ticket... ignore question 1.
7a4b8bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7a4b8bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true!
Thanks again for the fix! I was just being vaguely paranoid about untested code going in, since this was already something that has potentially caused me a problem for months/years.
7a4b8bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did test it manually both with and without encryption with about a gigabyte of generated data and with a real use case while working on a streaming xlsx writer. Still an automated test would be preferable.
7a4b8bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆒