Repository navigation
Fix is_encrypted() on an XLS stream ending in a partial record header - #106
Merged
Merged
Conversation
has_record() read 4-byte record headers until read() returned nothing, so a Workbook stream ending in 1-3 bytes of padding raised struct.error. xlwt pads the stream with zeros to 4096 bytes, so this happens for many of its files. Treat a partial header as the end of the stream. Fixes nolze#83
Owner
|
Thank you for the fix! Thanks to your sample, I found that the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #106 +/- ##
==========================================
- Coverage 92.09% 91.52% -0.57%
==========================================
Files 15 15
Lines 1847 1841 -6
==========================================
- Hits 1701 1685 -16
- Misses 146 156 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #83.
Xls97File.is_encrypted()raisedstruct.error: unpack requires a buffer of 4 bytesfor many XLS files written by xlwt. xlwt pads theWorkbookstream with zeros to a multiple of 4096 bytes.has_record()reads that padding as empty 4-byte records, and when 1–3 bytes are left,unpack("<HH", h)fails, because it only stopped whenread(4)returned nothing. Whether a file is affected depends on its size: of six xlwt workbooks with 1, 2, 5, 10, 50 and 200 rows, four raised.has_record()now treats a partial header (fewer than 4 bytes) as the end of the stream, as you suggested in #83. This doesn't miss an encrypted file: inrc4cryptoapi_password.xlsandxor_password_123456789012345.xls,FilePassis the record directly afterBOF, so it is found before any padding. I leftskip_to()anditer_record()as they are.skip_to()is only called for a record that is known to be there, anditer_record()feeds decryption, where the trailing bytes should not be dropped silently.tests/test_xls_padding.pychecksis_encrypted()ontests/inputs/plain_xlwt_padding.xls, a 3-row workbook written by xlwt 1.3.0. It fails without the change and passes with it. The other tests and thexls97doctests pass. (test_clifails on my checkout with and without the change, becausetest_cli.shgot CRLF line endings on Windows.)