@@ -6605,16 +6605,26 @@ static int
6605
6605
assemble_emit_linetable_pair (struct assembler * a , int bdelta , int ldelta )
6606
6606
{
6607
6607
Py_ssize_t len = PyBytes_GET_SIZE (a -> a_lnotab );
6608
- if (a -> a_lnotab_off + 2 >= len ) {
6609
- if (_PyBytes_Resize (& a -> a_lnotab , len * 2 ) < 0 )
6608
+ if (a -> a_lnotab_off > INT_MAX - 2 ) {
6609
+ goto overflow ;
6610
+ }
6611
+ if (a -> a_lnotab_off >= len - 2 ) {
6612
+ if (len > INT_MAX / 2 ) {
6613
+ goto overflow ;
6614
+ }
6615
+ if (_PyBytes_Resize (& a -> a_lnotab , len * 2 ) < 0 ) {
6610
6616
return 0 ;
6617
+ }
6611
6618
}
6612
6619
unsigned char * lnotab = (unsigned char * ) PyBytes_AS_STRING (a -> a_lnotab );
6613
6620
lnotab += a -> a_lnotab_off ;
6614
6621
a -> a_lnotab_off += 2 ;
6615
6622
* lnotab ++ = bdelta ;
6616
6623
* lnotab ++ = ldelta ;
6617
6624
return 1 ;
6625
+ overflow :
6626
+ PyErr_SetString (PyExc_OverflowError , "line number table is too long" );
6627
+ return 0 ;
6618
6628
}
6619
6629
6620
6630
/* Appends a range to the end of the line number table. See
@@ -6687,21 +6697,27 @@ assemble_emit(struct assembler *a, struct instr *i)
6687
6697
int size , arg = 0 ;
6688
6698
Py_ssize_t len = PyBytes_GET_SIZE (a -> a_bytecode );
6689
6699
_Py_CODEUNIT * code ;
6690
-
6691
6700
arg = i -> i_oparg ;
6692
6701
size = instrsize (arg );
6693
6702
if (i -> i_lineno && !assemble_lnotab (a , i ))
6694
6703
return 0 ;
6704
+ if (a -> a_offset > INT_MAX - size ) {
6705
+ goto overflow ;
6706
+ }
6695
6707
if (a -> a_offset + size >= len / (int )sizeof (_Py_CODEUNIT )) {
6696
- if (len > PY_SSIZE_T_MAX / 2 )
6697
- return 0 ;
6708
+ if (len > INT_MAX / 2 ) {
6709
+ goto overflow ;
6710
+ }
6698
6711
if (_PyBytes_Resize (& a -> a_bytecode , len * 2 ) < 0 )
6699
6712
return 0 ;
6700
6713
}
6701
6714
code = (_Py_CODEUNIT * )PyBytes_AS_STRING (a -> a_bytecode ) + a -> a_offset ;
6702
6715
a -> a_offset += size ;
6703
6716
write_op_arg (code , i -> i_opcode , arg , size );
6704
6717
return 1 ;
6718
+ overflow :
6719
+ PyErr_SetString (PyExc_OverflowError , "bytecode is too long" );
6720
+ return 0 ;
6705
6721
}
6706
6722
6707
6723
static void
0 commit comments