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
1b85c71a
Unverified
Kaydet (Commit)
1b85c71a
authored
Haz 10, 2018
tarafından
Tal Einat
Kaydeden (comit)
GitHub
Haz 10, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33770: improve base64 exception message for encoded inputs of invalid length (#7416)
üst
98a0e466
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletion
+41
-1
test_binascii.py
Lib/test/test_binascii.py
+28
-0
2018-06-05-11-29-26.bpo-33770.oBhxxw.rst
...S.d/next/Library/2018-06-05-11-29-26.bpo-33770.oBhxxw.rst
+1
-0
binascii.c
Modules/binascii.c
+12
-1
No files found.
Lib/test/test_binascii.py
Dosyayı görüntüle @
1b85c71a
...
...
@@ -110,6 +110,34 @@ class BinASCIITest(unittest.TestCase):
# empty strings. TBD: shouldn't it raise an exception instead ?
self
.
assertEqual
(
binascii
.
a2b_base64
(
self
.
type2test
(
fillers
)),
b
''
)
def
test_base64errors
(
self
):
# Test base64 with invalid padding
def
assertIncorrectPadding
(
data
):
with
self
.
assertRaisesRegex
(
binascii
.
Error
,
r'(?i)Incorrect padding'
):
binascii
.
a2b_base64
(
self
.
type2test
(
data
))
assertIncorrectPadding
(
b
'ab'
)
assertIncorrectPadding
(
b
'ab='
)
assertIncorrectPadding
(
b
'abc'
)
assertIncorrectPadding
(
b
'abcdef'
)
assertIncorrectPadding
(
b
'abcdef='
)
assertIncorrectPadding
(
b
'abcdefg'
)
assertIncorrectPadding
(
b
'a=b='
)
assertIncorrectPadding
(
b
'a
\n
b='
)
# Test base64 with invalid number of valid characters (1 mod 4)
def
assertInvalidLength
(
data
):
with
self
.
assertRaisesRegex
(
binascii
.
Error
,
r'(?i)invalid.+length'
):
binascii
.
a2b_base64
(
self
.
type2test
(
data
))
assertInvalidLength
(
b
'a'
)
assertInvalidLength
(
b
'a='
)
assertInvalidLength
(
b
'a=='
)
assertInvalidLength
(
b
'a==='
)
assertInvalidLength
(
b
'a'
*
5
)
assertInvalidLength
(
b
'a'
*
(
4
*
87
+
1
))
assertInvalidLength
(
b
'A
\t
B
\n
C ??DE'
)
# only 5 valid characters
def
test_uu
(
self
):
MAX_UU
=
45
for
backtick
in
(
True
,
False
):
...
...
Misc/NEWS.d/next/Library/2018-06-05-11-29-26.bpo-33770.oBhxxw.rst
0 → 100644
Dosyayı görüntüle @
1b85c71a
improve base64 exception message for encoded inputs of invalid length
Modules/binascii.c
Dosyayı görüntüle @
1b85c71a
...
...
@@ -510,7 +510,18 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data)
}
if
(
leftbits
!=
0
)
{
PyErr_SetString
(
Error
,
"Incorrect padding"
);
if
(
leftbits
==
6
)
{
/*
** There is exactly one extra valid, non-padding, base64 character.
** This is an invalid length, as there is no possible input that
** could encoded into such a base64 string.
*/
PyErr_SetString
(
Error
,
"Invalid base64-encoded string: "
"length cannot be 1 more than a multiple of 4"
);
}
else
{
PyErr_SetString
(
Error
,
"Incorrect padding"
);
}
_PyBytesWriter_Dealloc
(
&
writer
);
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