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
ea4b46f9
Kaydet (Commit)
ea4b46f9
authored
Nis 12, 2011
tarafından
Nadeem Vawda
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix 64-bit safety issue in BZ2Compressor and BZ2Decompressor.
üst
b30f1b41
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
10 deletions
+59
-10
test_bz2.py
Lib/test/test_bz2.py
+35
-1
_bz2module.c
Modules/_bz2module.c
+24
-9
No files found.
Lib/test/test_bz2.py
Dosyayı görüntüle @
ea4b46f9
#!/usr/bin/env python3
from
test
import
support
from
test.support
import
TESTFN
from
test.support
import
TESTFN
,
precisionbigmemtest
,
_4G
import
unittest
from
io
import
BytesIO
import
os
import
random
import
subprocess
import
sys
...
...
@@ -415,6 +416,23 @@ class BZ2CompressorTest(BaseTest):
data
+=
bz2c
.
flush
()
self
.
assertEqual
(
self
.
decompress
(
data
),
self
.
TEXT
)
@precisionbigmemtest
(
size
=
_4G
+
100
,
memuse
=
2
)
def
testCompress4G
(
self
,
size
):
# "Test BZ2Compressor.compress()/flush() with >4GiB input"
bz2c
=
BZ2Compressor
()
data
=
b
"x"
*
size
try
:
compressed
=
bz2c
.
compress
(
data
)
compressed
+=
bz2c
.
flush
()
finally
:
data
=
None
# Release memory
data
=
bz2
.
decompress
(
compressed
)
try
:
self
.
assertEqual
(
len
(
data
),
size
)
self
.
assertEqual
(
len
(
data
.
strip
(
b
"x"
)),
0
)
finally
:
data
=
None
class
BZ2DecompressorTest
(
BaseTest
):
def
test_Constructor
(
self
):
self
.
assertRaises
(
TypeError
,
BZ2Decompressor
,
42
)
...
...
@@ -453,6 +471,22 @@ class BZ2DecompressorTest(BaseTest):
text
=
bz2d
.
decompress
(
self
.
DATA
)
self
.
assertRaises
(
EOFError
,
bz2d
.
decompress
,
b
"anything"
)
@precisionbigmemtest
(
size
=
_4G
+
100
,
memuse
=
3
)
def
testDecompress4G
(
self
,
size
):
# "Test BZ2Decompressor.decompress() with >4GiB input"
blocksize
=
10
*
1024
*
1024
block
=
random
.
getrandbits
(
blocksize
*
8
)
.
to_bytes
(
blocksize
,
'little'
)
try
:
data
=
block
*
(
size
//
blocksize
+
1
)
compressed
=
bz2
.
compress
(
data
)
bz2d
=
BZ2Decompressor
()
decompressed
=
bz2d
.
decompress
(
compressed
)
self
.
assertTrue
(
decompressed
==
data
)
finally
:
data
=
None
compressed
=
None
decompressed
=
None
class
FuncTest
(
BaseTest
):
"Test module functions"
...
...
Modules/_bz2module.c
Dosyayı görüntüle @
ea4b46f9
...
...
@@ -36,6 +36,8 @@
#define RELEASE_LOCK(obj)
#endif
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
typedef
struct
{
PyObject_HEAD
...
...
@@ -145,8 +147,10 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
if
(
result
==
NULL
)
return
NULL
;
c
->
bzs
.
next_in
=
data
;
/* FIXME This is not 64-bit clean - avail_in is an int. */
c
->
bzs
.
avail_in
=
len
;
/* On a 64-bit system, len might not fit in avail_in (an unsigned int).
Do compression in chunks of no more than UINT_MAX bytes each. */
c
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
len
-=
c
->
bzs
.
avail_in
;
c
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
);
c
->
bzs
.
avail_out
=
PyBytes_GET_SIZE
(
result
);
for
(;;)
{
...
...
@@ -161,6 +165,11 @@ compress(BZ2Compressor *c, char *data, size_t len, int action)
if
(
catch_bz2_error
(
bzerror
))
goto
error
;
if
(
c
->
bzs
.
avail_in
==
0
&&
len
>
0
)
{
c
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
len
-=
c
->
bzs
.
avail_in
;
}
/* In regular compression mode, stop when input data is exhausted.
In flushing mode, stop when all buffered data has been flushed. */
if
((
action
==
BZ_RUN
&&
c
->
bzs
.
avail_in
==
0
)
||
...
...
@@ -354,8 +363,10 @@ decompress(BZ2Decompressor *d, char *data, size_t len)
if
(
result
==
NULL
)
return
result
;
d
->
bzs
.
next_in
=
data
;
/* FIXME This is not 64-bit clean - avail_in is an int. */
d
->
bzs
.
avail_in
=
len
;
/* On a 64-bit system, len might not fit in avail_in (an unsigned int).
Do decompression in chunks of no more than UINT_MAX bytes each. */
d
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
len
-=
d
->
bzs
.
avail_in
;
d
->
bzs
.
next_out
=
PyBytes_AS_STRING
(
result
);
d
->
bzs
.
avail_out
=
PyBytes_GET_SIZE
(
result
);
for
(;;)
{
...
...
@@ -371,17 +382,21 @@ decompress(BZ2Decompressor *d, char *data, size_t len)
goto
error
;
if
(
bzerror
==
BZ_STREAM_END
)
{
d
->
eof
=
1
;
if
(
d
->
bzs
.
avail_in
>
0
)
{
/* Save leftover input to unused_data */
len
+=
d
->
bzs
.
avail_in
;
if
(
len
>
0
)
{
/* Save leftover input to unused_data */
Py_CLEAR
(
d
->
unused_data
);
d
->
unused_data
=
PyBytes_FromStringAndSize
(
d
->
bzs
.
next_in
,
d
->
bzs
.
avail_in
);
d
->
unused_data
=
PyBytes_FromStringAndSize
(
d
->
bzs
.
next_in
,
len
);
if
(
d
->
unused_data
==
NULL
)
goto
error
;
}
break
;
}
if
(
d
->
bzs
.
avail_in
==
0
)
break
;
if
(
d
->
bzs
.
avail_in
==
0
)
{
if
(
len
==
0
)
break
;
d
->
bzs
.
avail_in
=
MIN
(
len
,
UINT_MAX
);
len
-=
d
->
bzs
.
avail_in
;
}
if
(
d
->
bzs
.
avail_out
==
0
)
{
if
(
grow_buffer
(
&
result
)
<
0
)
goto
error
;
...
...
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