File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -552,6 +552,9 @@ def test_count_overflow(self):
552552 hugecount2 = '{}b{}H' .format (sys .maxsize // 2 , sys .maxsize // 2 )
553553 self .assertRaises (struct .error , struct .calcsize , hugecount2 )
554554
555+ hugecount3 = '{}i{}q' .format (sys .maxsize // 4 , sys .maxsize // 8 )
556+ self .assertRaises (struct .error , struct .calcsize , hugecount3 )
557+
555558 def test_trailing_counter (self ):
556559 store = array .array ('b' , b' ' * 100 )
557560
Original file line number Diff line number Diff line change @@ -1678,7 +1678,15 @@ prepare_s(PyStructObject *self)
16781678 case 's' : _Py_FALLTHROUGH ;
16791679 case 'p' : len ++ ; ncodes ++ ; break ;
16801680 case 'x' : break ;
1681- default : len += num ; if (num ) ncodes ++ ; break ;
1681+ default :
1682+ if (num > PY_SSIZE_T_MAX - len ) {
1683+ goto overflow ;
1684+ }
1685+ len += num ;
1686+ if (num ) {
1687+ ncodes ++ ;
1688+ }
1689+ break ;
16821690 }
16831691
16841692 itemsize = e -> size ;
You can’t perform that action at this time.
0 commit comments