Repository navigation
Closed
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 21872 |
|---|---|
| Nosy | @gpshead, @4kir4, @peterjc, @serhiy-storchaka, @MojoVampire, @animalize, @miss-islington, @websurfer5 |
| PRs | |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2019-09-12.15:25:19.616>
created_at = <Date 2014-06-25.18:28:55.827>
labels = ['3.7', '3.8', 'type-bug', 'library', '3.9']
title = 'LZMA library sometimes fails to decompress a file'
updated_at = <Date 2019-09-14.04:31:45.330>
user = 'https://bugs.python.org/vnummela'bugs.python.org fields:
activity = <Date 2019-09-14.04:31:45.330>
actor = 'malin'
assignee = 'none'
closed = True
closed_date = <Date 2019-09-12.15:25:19.616>
closer = 'gregory.p.smith'
components = ['Library (Lib)']
creation = <Date 2014-06-25.18:28:55.827>
creator = 'vnummela'
dependencies = []
files = ['35779', '35822', '37241', '40612', '47349', '48391', '48425']
hgrepos = []
issue_num = 21872
keywords = ['patch']
message_count = 20.0
messages = ['221566', '221583', '221597', '221599', '221784', '222052', '231466', '231467', '251784', '309005', '344530', '344668', '345491', '345971', '345972', '352176', '352183', '352185', '352200', '352405']
nosy_count = 13.0
nosy_names = ['gregory.p.smith', 'nadeem.vawda', 'akira', 'maubp', 'serhiy.storchaka', 'Esa.Peuha', 'josh.r', 'malin', 'vnummela', 'kenorb', 'peremen', 'miss-islington', 'Jeffrey.Kintscher']
pr_nums = ['14048', '16054', '16055']
priority = 'normal'
resolution = 'fixed'
stage = 'commit review'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue21872'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']Metadata
Metadata
Assignees
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
vnummela commentedon Jun 25, 2014
Python lzma library sometimes fails to decompress a file, even though the file does not appear to be corrupt.
Originally discovered with OS X 10.9 / Python 2.7.7 / bacports.lzma
Now also reproduced on OS X / Python 3.4 / lzma, please see
peterjc/backports.lzma#6 for more details.
Two example files are provided, a good one and a bad one. Both are compressed using the older lzma algorithm (not xz). An attempt to decompress the 'bad' file raises "EOFError: Compressed file ended before the end-of-stream marker was reached."
The 'bad' file appears to be ok, because
The example files contain tick data and have been downloaded from the Dukascopy bank's historical data feed service. The service is well known for it's high data quality and utilised by multiple analysis SW platforms. Thus I think it is unlikely that a file integrity issue on their end would have gone unnoticed.
The error occurs relatively rarely; only around 1 - 5 times per 1000 downloaded files.
MojoVampire commentedon Jun 25, 2014
Just to be clear, when you say "1 - 5 times per 1000 downloaded files", have you confirmed that redownloading the same file a second time produces the same error? Just making sure we've ruled out corruption during transfer over the network; small errors might make it past one decompressor with minimal effect in the midst of a huge data file, while a more stringent error checking decompressor would reject them.
serhiy-storchaka commentedon Jun 26, 2014
This is similar to bpo-1159051. We need a way to say "read as much as possible without error and raise EOFError only on next read".
vnummela commentedon Jun 26, 2014
My stats so far:
As of writing this, I have attempted to decompress about 5000 downloaded files (two years of tick data). 25 'bad' files were found within this lot.
I re-downloaded all of them, plus about 500 other files as the minimum lot the server supplies is 24 hours / files at a time.
I compared all these 528 file pairs using hashlib.md5 and got identical hashes for all of them.
I guess what I should do next is to go through the decompressed data and look for suspicious anomalies, but unfortunately I don't have the tools in place to do that quite yet.
EsaPeuha commentedon Jun 28, 2014
This code
prints this
8191 36243 45480 True
8192 36251 45473 False
8193 36253 45475 False
8194 36260 45480 True
It seems to me that this is a subtle bug in liblzma; if the input stream to the incremental decompressor is broken at the wrong place, the internal state of the decompressor is corrupted. For this particular file, it happens when the break occurs after reading 8192 or 8193 bytes, and lzma.py happens to use a buffer of 8192 bytes. There is nothing wrong with the compressed file, since lzma.py decompresses it correctly if the buffer size is set to almost any other value.
vnummela commentedon Jul 1, 2014
Uploading a few more 'bad' lzma files for testing.
4kir4 commentedon Nov 21, 2014
@esa changing the buffer size helps with some "bad" files
but lzma module still fails on some files.
I've uploaded decompress-example-files.py script that demonstrates it.
4kir4 commentedon Nov 21, 2014
If lzma._BUFFER_SIZE is less than 2048 then all example files are
decompressed successfully (at least lzma module produces the same
results as xz utility)
kenorb commentedon Sep 28, 2015
The same with this attached file. It fails with Python 3.5 (small buffers like 128, 255, 1023, etc.) , but it seems to work in Python 3.4 with lzma._BUFFER_SIZE = 1023. So it looks like something regressed.
peremen commentedon Dec 24, 2017
Hi, I think I encountered this bug with Ubuntu 17.10 / Python 3.6.3. The same error was triggered by Python's LZMA library, while the xz command line tool can extract the problematic file. Not sure whether there is the bug in 3.7/3.8. I am attaching the problematic archives, they should contain UTF-16LE encoded text.
websurfer5 commentedon Jun 4, 2019
I adapted the example in msg221784:
which outputs this using both 3.7.3 and 3.8.0a3+ on macOS 10.14.4:
648 2682 45479 False
1834 7442 45479 False
2766 11667 45473 False
2767 11668 45474 False
3591 15428 45473 False
5051 21743 45473 False
5052 21745 45475 False
5589 24387 45475 False
5590 24388 45476 False
6560 28823 45476 False
6561 28824 45477 False
7327 32325 45474 False
8192 36251 45473 False
8193 36253 45475 False
8368 37283 45475 False
8369 37285 45477 False
So, yes, still an active bug.
animalize commentedon Jun 5, 2019
fix-bug.diff fixes this bug, I will submit a PR after thoroughly understanding the problem.
animalize commentedon Jun 13, 2019
I wrote a review guide in PR 14048.
animalize commentedon Jun 18, 2019
I investigated this problem.
Here is the toggle conditions:
Otherwise, liblzma's internal state doesn't hold any bytes that can be output.
Good news is:
Attached file test_bad_files.py, test
DecompressReader.read(size=-1)function [1] with different max_length values (from -1 to 1000, exclude 0), can ensure that the needs_input mechanism works properly.Usage: modify
DIRvariable to bad files' folder.[1] https://github.com/python/cpython/blob/v3.8.0b1/Lib/_compression.py#L72-L111
animalize commentedon Jun 18, 2019
toggle conditions -> trigger conditions
gpshead commentedon Sep 12, 2019
New changeset 4ffd05d by Gregory P. Smith (animalize) in branch 'master':
bpo-21872: fix lzma library decompresses data incompletely (GH-14048)
4ffd05d
miss-islington commentedon Sep 12, 2019
New changeset 824407f by Miss Islington (bot) in branch '3.8':
bpo-21872: fix lzma library decompresses data incompletely (GH-14048)
824407f
miss-islington commentedon Sep 12, 2019
New changeset a3c53a1 by Miss Islington (bot) in branch '3.7':
bpo-21872: fix lzma library decompresses data incompletely (GH-14048)
a3c53a1
gpshead commentedon Sep 12, 2019
thanks!
animalize commentedon Sep 14, 2019
Some memos:
1, In liblzma, these missing bytes were copied inside
dict_repeatfunction:788 case SEQ_COPY:
789 // Repeat len bytes from distance of rep0.
790 if (unlikely(dict_repeat(&dict, rep0, &len))) {
See liblzma's source code (xz-5.2 branch):
https://git.tukaani.org/?p=xz.git;a=blob;f=src/liblzma/lzma/lzma_decoder.c
2, Above replies said xz's command line tools can extract the problematic files successfully.
This is because xz checks
if (avail_out == 0)first, then checksif (avail_in == 0)See
uncompressfunction in this source code (xz-5.2 branch):https://git.tukaani.org/?p=xz.git;a=blob;f=src/xzdec/xzdec.c;hb=refs/heads/v5.2
This check order just avoids the problem.