@@ -82,19 +82,20 @@ typedef struct Header {
82
82
} Header ;
83
83
84
84
85
- static int getnum (const char * * fmt , int df ) {
85
+ static int getnum (lua_State * L , const char * * fmt , int df ) {
86
86
if (!isdigit (* * fmt )) /* no number? */
87
87
return df ; /* return default value */
88
88
else {
89
89
int a = 0 ;
90
90
do {
91
+ if (a > (INT_MAX / 10 ) || a * 10 > (INT_MAX - (* * fmt - '0' )))
92
+ luaL_error (L , "integral size overflow" );
91
93
a = a * 10 + * ((* fmt )++ ) - '0' ;
92
94
} while (isdigit (* * fmt ));
93
95
return a ;
94
96
}
95
97
}
96
98
97
-
98
99
#define defaultoptions (h ) ((h)->endian = native.endian, (h)->align = 1)
99
100
100
101
@@ -108,9 +109,9 @@ static size_t optsize (lua_State *L, char opt, const char **fmt) {
108
109
case 'f' : return sizeof (float );
109
110
case 'd' : return sizeof (double );
110
111
case 'x' : return 1 ;
111
- case 'c' : return getnum (fmt , 1 );
112
+ case 'c' : return getnum (L , fmt , 1 );
112
113
case 'i' : case 'I' : {
113
- int sz = getnum (fmt , sizeof (int ));
114
+ int sz = getnum (L , fmt , sizeof (int ));
114
115
if (sz > MAXINTSIZE )
115
116
luaL_error (L , "integral size %d is larger than limit of %d" ,
116
117
sz , MAXINTSIZE );
@@ -143,7 +144,7 @@ static void controloptions (lua_State *L, int opt, const char **fmt,
143
144
case '>' : h -> endian = BIG ; return ;
144
145
case '<' : h -> endian = LITTLE ; return ;
145
146
case '!' : {
146
- int a = getnum (fmt , MAXALIGN );
147
+ int a = getnum (L , fmt , MAXALIGN );
147
148
if (!isp2 (a ))
148
149
luaL_error (L , "alignment %d is not a power of 2" , a );
149
150
h -> align = a ;
0 commit comments