diff --git a/Lib/pickle.py b/Lib/pickle.py index 8be7a8d3621..d5773e24c77 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -615,7 +615,11 @@ def load_none(self): dispatch[NONE] = load_none def load_int(self): - self.append(int(self.readline()[:-1])) + data = self.readline() + try: + self.append(int(data)) + except ValueError: + self.append(long(data)) dispatch[INT] = load_int def load_binint(self): diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index fa3fb89d33f..fa3ddf43ad7 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -221,3 +221,18 @@ def dotest(pickle): repr(s), got)) n = n >> 1 + + # Fake a pickle from a sizeof(long)==8 box. + maxint64 = (1L << 63) - 1 + data = 'I' + str(maxint64) + '\n.' + got = pickle.loads(data) + if maxint64 != got: + raise TestFailed("maxint64 test failed %r %r" % (maxint64, got)) + # Try too with a bogus literal. + data = 'I' + str(maxint64) + 'JUNK\n.' + try: + got = pickle.loads(data) + except ValueError: + pass + else: + raise TestFailed("should have raised error on bogus INT literal")