New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A typo in a constant in cp932 codec #79375
Comments
UBSan with -fsanitize=implicit-integer-truncation found a suspicious one: Indeed, the wrong constant was used (the correct one is used in corresponding decoder code at cpython/Modules/cjkcodecs/_codecs_jp.c Line 105 in fd512d7
All Python versions are affected, but I've marked 3.8 only since I'm not sure what the policy for backporting such changes is. |
Maybe add asserts in OUTBYTE1() and similar macros to prevent similar errors in future? |
I like the idea. Make sure that: 0 <= ch <= 255? |
I've added 'assert' to macros. Since 'typeof' seems to be disallowed in Python, I've used 'unsigned int' as the type of an intermediate variable. |
Converting to unsigned int can unnecessary widen the value or truncate higher bits. On other side, testing "0 <= (c)" can emit a compiler warning if c is unsigned. Maybe test "Py_CHARMASK(c) == (c)"? |
This is a good alternative if multiple evaluation of 'c' is acceptable. Though I'd prefer '(unsigned char)c == c' for this style of fixing because it is bit closer to what happens in '((*outbuf)[i]) = c'. |
I've checked than other macros in Modules/cjkcodecs/cjkcodecs.h don't avoid multiple argument evaluation (e.g. OUTCHAR2, _TRYMAP_ENC), so I've changed 'assert' to a variant of what Serhiy suggested. |
OUTCHAR2 is a wrong example. Other examples are NEXT_IN, NEXT_OUT. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: