Uh oh!
There was an error while loading. Please reload this page.
gh-127740: For odd-length input to bytes.fromhex(...) change the error message to ValueError: fromhex() arg must be of even length - #127756
Conversation
…e error message to ValueError: fromhex() arg must be of even length
srinivasreddy
commented
Dec 9, 2024
@hauntsaninja Please review again? |
picnixz
left a comment
There was a problem hiding this comment.
I think hauntsaninja wanted the error check at the level of the error label, not during the parsing. Since the current code jumps to error in case of an odd-length input, is it possible to check that it's indeed odd-length when creating the error?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cfbolz
commented
Dec 10, 2024
Yes, I agree with @picnixz and @hauntsaninja, the new if is done for every character pair now, which makes things less efficient. I suggest moving the new check into the condition just below. |
cfbolz
commented
Dec 10, 2024
No, that's not what I meant, sorry for being unclear. many invalid byte values are mapped to 37, not just null. So instead, you need to check for your original condition |
srinivasreddy
commented
Dec 10, 2024
@cfbolz what do you think now ? |
cfbolz
commented
Dec 10, 2024
@srinivasreddy code looks good now, imo. please add a news entry though. |
| self.assertRaises(ValueError, self.type2test.fromhex, '12 \x00 34') | ||
| # For odd number of character(s) | ||
| for value in ("a", "aaa", "deadbee"): |
There was a problem hiding this comment.
nit: would be nice to have a test case where the string is of even length, e.g. " aaa" and test cases where we check the error message for " aa a " / " aa a a "
There was a problem hiding this comment.
sorry for going ahead and merging @hauntsaninja. I should have waited for more input from you.
There was a problem hiding this comment.
oh all good, was just a nit and commits are cheap :-) thanks for reviewing!
Kodiologist
commented
Dec 12, 2024
That was fast. Thanks. |
…e error message to ValueError: fromhex() arg must be of even length (python#127756)
bytes.fromhexis cryptic #127740