File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -309,14 +309,16 @@ static int b_unpack (lua_State *L) {
309309 const char * fmt = luaL_checkstring (L , 1 );
310310 size_t ld ;
311311 const char * data = luaL_checklstring (L , 2 , & ld );
312- size_t pos = luaL_optinteger (L , 3 , 1 ) - 1 ;
312+ size_t pos = luaL_optinteger (L , 3 , 1 );
313+ luaL_argcheck (L , pos > 0 , 3 , "offset must be 1 or greater" );
314+ pos -- ;
313315 defaultoptions (& h );
314316 lua_settop (L , 2 );
315317 while (* fmt ) {
316318 int opt = * fmt ++ ;
317319 size_t size = optsize (L , opt , & fmt );
318320 pos += gettoalign (pos , & h , opt , size );
319- luaL_argcheck (L , pos + size <= ld , 2 , "data string too short" );
321+ luaL_argcheck (L , size <= ld && pos <= ld - size , 2 , "data string too short" );
320322 luaL_checkstack (L , 2 , "too many results" );
321323 switch (opt ) {
322324 case 'b' : case 'B' : case 'h' : case 'H' :
You can’t perform that action at this time.
0 commit comments