classification
Title: base64.b64decode() with validate=True does not raise for a trailing \n
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2019-12-15 17:21 by serhiy.storchaka, last changed 2020-01-05 13:33 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17616 merged serhiy.storchaka, 2019-12-15 17:26
PR 17833 merged miss-islington, 2020-01-05 12:16
PR 17834 merged miss-islington, 2020-01-05 12:16
Messages (4)
msg358438 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-12-15 17:21
If validate=True is passed to base64.b64decode(), it should raise a binascii.Error if the input contains any character not from the acceptable alphabet.

But it does not raise if the input ends with a single \n. It raises if the input ends with a multiple \n or with any other whitespace character. Only a single \n is accepted.

This is an implementation artifact. A regular exception ending with $ is used to validate an input. But $ matches not only end of string. It matches also an empty string before the trailing \n.

Similar errors are also occurred in other sites. I'll open separate issues for different cases.
msg359334 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-01-05 12:15
New changeset b19c0d77e6f25ea831ab608c71f15d0d9266c8c4 by Serhiy Storchaka in branch 'master':
bpo-39055: Reject a trailing \n in base64.b64decode() with validate=True. (GH-17616)
https://github.com/python/cpython/commit/b19c0d77e6f25ea831ab608c71f15d0d9266c8c4
msg359337 - (view) Author: miss-islington (miss-islington) Date: 2020-01-05 12:32
New changeset 3bdb2d9daf3ce41b325bd508e3dd29041e85dd1f by Miss Islington (bot) in branch '3.7':
bpo-39055: Reject a trailing \n in base64.b64decode() with validate=True. (GH-17616)
https://github.com/python/cpython/commit/3bdb2d9daf3ce41b325bd508e3dd29041e85dd1f
msg359340 - (view) Author: miss-islington (miss-islington) Date: 2020-01-05 12:36
New changeset 34aa3e71dc52c1a31336302905b9ac011a310412 by Miss Islington (bot) in branch '3.8':
bpo-39055: Reject a trailing \n in base64.b64decode() with validate=True. (GH-17616)
https://github.com/python/cpython/commit/34aa3e71dc52c1a31336302905b9ac011a310412
History
Date User Action Args
2020-01-05 13:33:45serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-01-05 12:36:51miss-islingtonsetmessages: + msg359340
2020-01-05 12:32:48miss-islingtonsetnosy: + miss-islington
messages: + msg359337
2020-01-05 12:16:08miss-islingtonsetpull_requests: + pull_request17261
2020-01-05 12:16:02miss-islingtonsetpull_requests: + pull_request17260
2020-01-05 12:15:53serhiy.storchakasetmessages: + msg359334
2019-12-15 17:26:51serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request17087
2019-12-15 17:21:28serhiy.storchakacreate