Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9c72ebc9
Kaydet (Commit)
9c72ebc9
authored
Ara 04, 2013
tarafından
Nadeem Vawda
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#19839: Fix lzma module's handling of non-lzma data at EOF.
üst
1de19ac7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
8 deletions
+48
-8
lzma.py
Lib/lzma.py
+21
-7
test_lzma.py
Lib/test/test_lzma.py
+26
-0
NEWS
Misc/NEWS
+1
-1
No files found.
Lib/lzma.py
Dosyayı görüntüle @
9c72ebc9
...
...
@@ -224,11 +224,18 @@ class LZMAFile(io.BufferedIOBase):
raise
EOFError
(
"Compressed file ended before the "
"end-of-stream marker was reached"
)
# Continue to next stream.
if
self
.
_decompressor
.
eof
:
# Continue to next stream.
self
.
_decompressor
=
LZMADecompressor
(
**
self
.
_init_args
)
self
.
_buffer
=
self
.
_decompressor
.
decompress
(
rawblock
)
try
:
self
.
_buffer
=
self
.
_decompressor
.
decompress
(
rawblock
)
except
LZMAError
:
# Trailing data isn't a valid compressed stream; ignore it.
self
.
_mode
=
_MODE_READ_EOF
self
.
_size
=
self
.
_pos
return
False
else
:
self
.
_buffer
=
self
.
_decompressor
.
decompress
(
rawblock
)
# Read data until EOF.
# If return_data is false, consume the data without returning it.
...
...
@@ -444,11 +451,18 @@ def decompress(data, format=FORMAT_AUTO, memlimit=None, filters=None):
results
=
[]
while
True
:
decomp
=
LZMADecompressor
(
format
,
memlimit
,
filters
)
results
.
append
(
decomp
.
decompress
(
data
))
try
:
res
=
decomp
.
decompress
(
data
)
except
LZMAError
:
if
results
:
break
# Leftover data is not a valid LZMA/XZ stream; ignore it.
else
:
raise
# Error on the first iteration; bail out.
results
.
append
(
res
)
if
not
decomp
.
eof
:
raise
LZMAError
(
"Compressed data ended before the "
"end-of-stream marker was reached"
)
if
not
decomp
.
unused_data
:
return
b
""
.
join
(
results
)
# There is unused data left over. Proceed to next stream.
data
=
decomp
.
unused_data
if
not
data
:
break
return
b
""
.
join
(
results
)
Lib/test/test_lzma.py
Dosyayı görüntüle @
9c72ebc9
...
...
@@ -313,6 +313,8 @@ class CompressDecompressFunctionTestCase(unittest.TestCase):
format
=
lzma
.
FORMAT_RAW
,
filters
=
FILTERS_RAW_4
)
def
test_decompress_bad_input
(
self
):
with
self
.
assertRaises
(
LZMAError
):
lzma
.
decompress
(
COMPRESSED_BOGUS
)
with
self
.
assertRaises
(
LZMAError
):
lzma
.
decompress
(
COMPRESSED_RAW_1
)
with
self
.
assertRaises
(
LZMAError
):
...
...
@@ -348,6 +350,16 @@ class CompressDecompressFunctionTestCase(unittest.TestCase):
ddata
=
lzma
.
decompress
(
COMPRESSED_XZ
+
COMPRESSED_ALONE
)
self
.
assertEqual
(
ddata
,
INPUT
*
2
)
# Test robust handling of non-LZMA data following the compressed stream(s).
def
test_decompress_trailing_junk
(
self
):
ddata
=
lzma
.
decompress
(
COMPRESSED_XZ
+
COMPRESSED_BOGUS
)
self
.
assertEqual
(
ddata
,
INPUT
)
def
test_decompress_multistream_trailing_junk
(
self
):
ddata
=
lzma
.
decompress
(
COMPRESSED_XZ
*
3
+
COMPRESSED_BOGUS
)
self
.
assertEqual
(
ddata
,
INPUT
*
3
)
class
TempFile
:
"""Context manager - creates a file, and deletes it on __exit__."""
...
...
@@ -658,6 +670,14 @@ class FileTestCase(unittest.TestCase):
finally
:
lzma
.
_BUFFER_SIZE
=
saved_buffer_size
def
test_read_trailing_junk
(
self
):
with
LZMAFile
(
BytesIO
(
COMPRESSED_XZ
+
COMPRESSED_BOGUS
))
as
f
:
self
.
assertEqual
(
f
.
read
(),
INPUT
)
def
test_read_multistream_trailing_junk
(
self
):
with
LZMAFile
(
BytesIO
(
COMPRESSED_XZ
*
5
+
COMPRESSED_BOGUS
))
as
f
:
self
.
assertEqual
(
f
.
read
(),
INPUT
*
5
)
def
test_read_from_file
(
self
):
with
TempFile
(
TESTFN
,
COMPRESSED_XZ
):
with
LZMAFile
(
TESTFN
)
as
f
:
...
...
@@ -687,6 +707,10 @@ class FileTestCase(unittest.TestCase):
with
LZMAFile
(
BytesIO
(
COMPRESSED_XZ
))
as
f
:
self
.
assertRaises
(
TypeError
,
f
.
read
,
None
)
def
test_read_bad_data
(
self
):
with
LZMAFile
(
BytesIO
(
COMPRESSED_BOGUS
))
as
f
:
self
.
assertRaises
(
LZMAError
,
f
.
read
)
def
test_read1
(
self
):
with
LZMAFile
(
BytesIO
(
COMPRESSED_XZ
))
as
f
:
blocks
=
[]
...
...
@@ -1192,6 +1216,8 @@ LAERTES
Farewell.
"""
COMPRESSED_BOGUS
=
b
"this is not a valid lzma stream"
COMPRESSED_XZ
=
(
b
"
\xfd
7zXZ
\x00\x00\x04\xe6\xd6\xb4
F
\x02\x00
!
\x01\x16\x00\x00\x00
t/
\xe5\xa3
"
b
"
\xe0\x07\x80\x03\xdf
]
\x00\x05\x14\x07
bX
\x19\xcd\xdd
n
\x98\x15\xe4\xb4\x9d
"
...
...
Misc/NEWS
Dosyayı görüntüle @
9c72ebc9
...
...
@@ -19,7 +19,7 @@ Library
-------
- Issue #19839: Fix regression in bz2 module'
s
handling
of
non
-
bzip2
data
at
EOF
.
EOF
,
and
analogous
bug
in
lzma
module
.
-
Issue
#
19138
:
doctest
's IGNORE_EXCEPTION_DETAIL now allows a match when
no exception detail exists (no colon following the exception'
s
name
,
or
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment