Skip to content

Commit 3e1c18a

Browse files
author
Thomas Heller
committed
Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
See there for a description. Added test case. Bugfix candidate for 2.2.x, not sure about previous versions: probably low priority, because virtually no one runs debug builds.
1 parent a625523 commit 3e1c18a

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Lib/test/test_marshal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ def to_little_endian_string(value, nbytes):
3939
base = 0
4040
else:
4141
base >>= 1
42+
43+
# Simple-minded check for SF 588452: Debug build crashes
44+
marshal.dumps([128] * 1000)

Python/marshal.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ w_string(char *s, int n, WFILE *p)
8484
static void
8585
w_short(int x, WFILE *p)
8686
{
87-
w_byte( x & 0xff, p);
88-
w_byte((x>> 8) & 0xff, p);
87+
w_byte((char)( x & 0xff), p);
88+
w_byte((char)((x>> 8) & 0xff), p);
8989
}
9090

9191
static void
9292
w_long(long x, WFILE *p)
9393
{
94-
w_byte((int)( x & 0xff), p);
95-
w_byte((int)((x>> 8) & 0xff), p);
96-
w_byte((int)((x>>16) & 0xff), p);
97-
w_byte((int)((x>>24) & 0xff), p);
94+
w_byte((char)( x & 0xff), p);
95+
w_byte((char)((x>> 8) & 0xff), p);
96+
w_byte((char)((x>>16) & 0xff), p);
97+
w_byte((char)((x>>24) & 0xff), p);
9898
}
9999

100100
#if SIZEOF_LONG > 4

0 commit comments

Comments
 (0)