Message242457
Hi,
There is a small bug in GB18030 decoder.
For 4-byte sequence, the legal range is:
0x81-0xFE for the 1st byte
0x30-0x39 for the 2nd byte
0x81-0xFE for the 3rd byte
0x30-0x39 for the 4th byte
The current code forgets to check 0xFE of the 1st and 3rd byte.
Therefore, there are 8630 illegal 4-byte sequences can be decoded by GB18030 codec, here is an example:
# legal sequence 0x81319130 is decoded to U+060A, it's fine.
b = bytes([0x81, 0x31, 0x81, 0x30])
uchar = b.decode('gb18030')
print(ord(uchar))
# illegal sequence 0x8130FF30 can be decoded to U+060A as well.
b = bytes([0x81, 0x30, 0xFF, 0x30])
uchar = b.decode('gb18030')
print(ord(uchar)) |
|
Date |
User |
Action |
Args |
2015-05-03 08:16:59 | malin | set | recipients:
+ malin, vstinner, ezio.melotti |
2015-05-03 08:16:59 | malin | set | messageid: <1430641019.11.0.12743813091.issue24117@psf.upfronthosting.co.za> |
2015-05-03 08:16:59 | malin | link | issue24117 messages |
2015-05-03 08:16:58 | malin | create | |
|