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
f78b1193
Kaydet (Commit)
f78b1193
authored
Nis 04, 2017
tarafından
Andrew Nester
Kaydeden (comit)
Serhiy Storchaka
Nis 04, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29649: Improve struct.pack_into() boundary error messages (#424)
üst
5de85a17
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
test_struct.py
Lib/test/test_struct.py
+20
-0
NEWS
Misc/NEWS
+3
-0
_struct.c
Modules/_struct.c
+30
-4
No files found.
Lib/test/test_struct.py
Dosyayı görüntüle @
f78b1193
...
...
@@ -578,6 +578,26 @@ class StructTest(unittest.TestCase):
self
.
check_sizeof
(
'0s'
,
1
)
self
.
check_sizeof
(
'0c'
,
0
)
def
test_boundary_error_message
(
self
):
regex
=
(
r'pack_into requires a buffer of at least 6 '
r'bytes for packing 1 bytes at offset 5 '
r'\(actual buffer size is 1\)'
)
with
self
.
assertRaisesRegex
(
struct
.
error
,
regex
):
struct
.
pack_into
(
'b'
,
bytearray
(
1
),
5
,
1
)
def
test_boundary_error_message_with_negative_offset
(
self
):
byte_list
=
bytearray
(
10
)
with
self
.
assertRaisesRegex
(
struct
.
error
,
r'no space to pack 4 bytes at offset -2'
):
struct
.
pack_into
(
'<I'
,
byte_list
,
-
2
,
123
)
with
self
.
assertRaisesRegex
(
struct
.
error
,
'offset -11 out of range for 10-byte buffer'
):
struct
.
pack_into
(
'<B'
,
byte_list
,
-
11
,
123
)
class
UnpackIteratorTest
(
unittest
.
TestCase
):
"""
...
...
Misc/NEWS
Dosyayı görüntüle @
f78b1193
...
...
@@ -303,6 +303,9 @@ Extension Modules
Library
-------
- bpo-29649: Improve struct.pack_into() exception messages for problems
with the buffer size and offset. Patch by Andrew Nester.
- bpo-29654: Support If-Modified-Since HTTP header (browser cache). Patch
by Pierre Quentel.
...
...
Modules/_struct.c
Dosyayı görüntüle @
f78b1193
...
...
@@ -1931,14 +1931,40 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames
}
/* Support negative offsets. */
if
(
offset
<
0
)
if
(
offset
<
0
)
{
/* Check that negative offset is low enough to fit data */
if
(
offset
+
soself
->
s_size
>
0
)
{
PyErr_Format
(
StructError
,
"no space to pack %zd bytes at offset %zd"
,
soself
->
s_size
,
offset
);
PyBuffer_Release
(
&
buffer
);
return
NULL
;
}
/* Check that negative offset is not crossing buffer boundary */
if
(
offset
+
buffer
.
len
<
0
)
{
PyErr_Format
(
StructError
,
"offset %zd out of range for %zd-byte buffer"
,
offset
,
buffer
.
len
);
PyBuffer_Release
(
&
buffer
);
return
NULL
;
}
offset
+=
buffer
.
len
;
}
/* Check boundaries */
if
(
offset
<
0
||
(
buffer
.
len
-
offset
)
<
soself
->
s_size
)
{
if
((
buffer
.
len
-
offset
)
<
soself
->
s_size
)
{
PyErr_Format
(
StructError
,
"pack_into requires a buffer of at least %zd bytes"
,
soself
->
s_size
);
"pack_into requires a buffer of at least %zd bytes for "
"packing %zd bytes at offset %zd "
"(actual buffer size is %zd)"
,
soself
->
s_size
+
offset
,
soself
->
s_size
,
offset
,
buffer
.
len
);
PyBuffer_Release
(
&
buffer
);
return
NULL
;
}
...
...
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