Skip to content

Commit 162ee5f

Browse files
committed
Bug [7b46bc7f85] UBSan on binary uuencode
1 parent 98f7401 commit 162ee5f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

generic/tclBinary.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,14 +2808,16 @@ BinaryEncodeUu(
28082808
}
28092809
*cursor++ = UueDigits[lineLen];
28102810
for (i = 0 ; i < lineLen ; i++) {
2811-
n <<= 8;
2811+
/* Left shift cast to unsigned type to prevent UB on overflow */
2812+
n = (Tcl_Size)((size_t)n << 8);
28122813
n |= data[offset++];
28132814
for (bits += 8; bits > 6 ; bits -= 6) {
28142815
*cursor++ = UueDigits[(n >> (bits - 6)) & 0x3F];
28152816
}
28162817
}
28172818
if (bits > 0) {
2818-
n <<= 8;
2819+
/* Left shift cast to unsigned type to prevent UB on overflow */
2820+
n = (Tcl_Size)((size_t)n << 8);
28192821
*cursor++ = UueDigits[(n >> (bits + 2)) & 0x3F];
28202822
bits = 0;
28212823
}

0 commit comments

Comments
 (0)