| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. An early length check would still be a good idea given that DNS IDNA label names cannot be more than 63 ASCII characters.
|
The code looks weird (already did before the change): RandAL = [stringprep.in_table_d1(x) for x in label]
any_in_table_d2 = any(stringprep.in_table_d2(x) for x in label)
for c in RandAL:
if c:
if any_in_table_d2:
raise UnicodeError("Violation of BIDI requirement 2")
if not RandAL[0] or not RandAL[-1]:
raise UnicodeError("Violation of BIDI requirement 3")
Doesn't make sense to run the same two inner checks multiple times (note they don't use c). Either they raise the first time or they never do. Is there a good reason it's not as follows? (Replaced the for+if with if any, unindented, and moved the D2 check back down where it was before the change). RandAL = [stringprep.in_table_d1(x) for x in label]
if any(RandAL):
if any(stringprep.in_table_d2(x) for x in label):
raise UnicodeError("Violation of BIDI requirement 2")
if not RandAL[0] or not RandAL[-1]:
raise UnicodeError("Violation of BIDI requirement 3")
I think it's only because the code was written in 2003 and any didn't exist yet (introduced in 2006). |
Sorry, something went wrong.
+10
Ahha, that explains so much. Thanks @pochmann! I was aiming for minimal diff once I profiled to find the hot spot, but this code is pretty gross. I'll go with your suggested version. Much cleaner. |
Sorry, something went wrong.
|
random observation: If someone wanted a truly minimal patch, putting a break at the end of the for c in RandAL: ... if c: ... block would also work. I went with the modern easier to understand suggestion from Stefan. |
Sorry, something went wrong.
| such as :mod:`urllib` http ``3xx`` redirects potentially allow for an attacker | ||
| to supply such a name. | ||
|
|
||
| Individual labels within an IDNA encoded DNS name will now raise an error early |
There was a problem hiding this comment.
I'm okay with leaving this length limit out either entirely - or just out of the backports if release managers are uncomfortable with this in a bugfix.
I view it as protection from other as yet unknown future idna or punycode decoder logic bugs to avoid wasting cpu time. The only reference numbers related to my arbitrary input length limit choice are: A DNS hostname is 255 bytes at most. A label within a DNS name is 63 bytes at most.
The "Nothing" characters in question that are removed in nameprep() in https://github.com/python/cpython/blob/main/Lib/encodings/idna.py#L18 are non-ascii unicode oddities.
Other IDNA decoding libraries in the wild like the well known ICU library do not limit the length at this level of API, instead leaving that to higher levels in the application:
Sorry, something went wrong.
|
cc'ing release managers @pablogsal and @ambv for feedback on the shape of this to backport. See the code review comment i left on the news entry. Q: backport (a) just the unnecessarily quadratic algorithm removal OR (b) also the added up front length check. I think either would be fine. The conservative backport choice would be (a). I'm happy to do either. |
Sorry, something went wrong.
thanks victor!
There was a problem hiding this comment.
LGTM.
Sorry, something went wrong.
|
Merging. I'll trigger the other backports from the 3.11 backport PR and let RMs chime in there. |
Sorry, something went wrong.
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. This also adds an early length check in IDNA decoding to outright reject huge inputs early on given the ultimate result is defined to be 63 or fewer characters. (cherry picked from commit d315722) Co-authored-by: Gregory P. Smith <greg@krypto.org>
|
GH-99222 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️Hi! The buildbot s390x Fedora Clang Installed 3.x has failed when building commit d315722. What do you need to do:
You can take a look at the buildbot page here: https://buildbot.python.org/all/#builders/531/builds/2842 Summary of the results of the build (if available): Click to see traceback logsfatal: unable to access 'https://github.com/python/cpython.git/': The requested URL returned error: 503
chmod: cannot access 'target/': No such file or directory
make: *** No rule to make target 'distclean'. Stop. |
Sorry, something went wrong.
) (pythonGH-99222) There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit d315722) (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
) (pythonGH-99222) There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit d315722) (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
) (pythonGH-99222) There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit d315722) (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit d315722) (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
|
The buildbot failed with: fatal: unable to access 'https://github.com/python/cpython.git/': The requested URL returned error: 503 |
Sorry, something went wrong.
Network issues should not mark a whole build as failure. I made buildbot change to mark next builds as "warning" rather than "failed" in this case: python/buildmaster-config#348 |
Sorry, something went wrong.
… (GH-99231) There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit d315722) (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
… (#99230) There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear. (cherry picked from commit d315722) (cherry picked from commit a6f6c3a) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Add a *limit* argument to nameprep to allow ToASCII and ToUnicode to reject extremely large input early. This replaces the check in python#99092, while allowing any number of harmless "characters mapped to nothing" (RFC 3454 §3.1). The default stays unlimited, to not change behaviour for users that call nameprep manually (and don't necessarily follow up with punycode).
Add a *limit* argument to nameprep to allow ToASCII and ToUnicode to reject extremely large input early. This replaces the check in #99092, while allowing any number of harmless "characters mapped to nothing" (RFC 3454 §3.1). The default stays unlimited, to not change behaviour for users that call nameprep manually (and don't necessarily follow up with punycode). Co-authored-by: Stan Ulbrych <stan@python.org>
| Back | FazBrowse Home | New Git URL |
There was an unnecessary quadratic loop in idna decoding. This restores the behavior to linear and adds an upfront length check to avoid even bothering the decoding attempt when clearly unreasonable.