@@ -385,6 +385,7 @@ void mp_encode_lua_table_as_array(lua_State *L, mp_buf *buf, int level) {
385
385
#endif
386
386
387
387
mp_encode_array (L ,buf ,len );
388
+ luaL_checkstack (L , 1 , "in function mp_encode_lua_table_as_array" );
388
389
for (j = 1 ; j <= len ; j ++ ) {
389
390
lua_pushnumber (L ,j );
390
391
lua_gettable (L ,-2 );
@@ -400,6 +401,7 @@ void mp_encode_lua_table_as_map(lua_State *L, mp_buf *buf, int level) {
400
401
* Lua API, we need to iterate a first time. Note that an alternative
401
402
* would be to do a single run, and then hack the buffer to insert the
402
403
* map opcodes for message pack. Too hackish for this lib. */
404
+ luaL_checkstack (L , 3 , "in function mp_encode_lua_table_as_map" );
403
405
lua_pushnil (L );
404
406
while (lua_next (L ,-2 )) {
405
407
lua_pop (L ,1 ); /* remove value, keep key for next iteration. */
@@ -515,10 +517,14 @@ int mp_pack(lua_State *L) {
515
517
if (nargs == 0 )
516
518
return luaL_argerror (L , 0 , "MessagePack pack needs input." );
517
519
520
+ if (!lua_checkstack (L , nargs ))
521
+ return luaL_argerror (L , 0 , "Too many arguments for MessagePack pack." );
522
+
518
523
buf = mp_buf_new (L );
519
524
for (i = 1 ; i <= nargs ; i ++ ) {
520
525
/* Copy argument i to top of stack for _encode processing;
521
526
* the encode function pops it from the stack when complete. */
527
+ luaL_checkstack (L , 1 , "in function mp_check" );
522
528
lua_pushvalue (L , i );
523
529
524
530
mp_encode_lua_type (L ,buf ,0 );
@@ -547,6 +553,7 @@ void mp_decode_to_lua_array(lua_State *L, mp_cur *c, size_t len) {
547
553
int index = 1 ;
548
554
549
555
lua_newtable (L );
556
+ luaL_checkstack (L , 1 , "in function mp_decode_to_lua_array" );
550
557
while (len -- ) {
551
558
lua_pushnumber (L ,index ++ );
552
559
mp_decode_to_lua_type (L ,c );
@@ -821,6 +828,9 @@ int mp_unpack_full(lua_State *L, int limit, int offset) {
821
828
* subtract the entire buffer size from the unprocessed size
822
829
* to get our next start offset */
823
830
int offset = len - c .left ;
831
+
832
+ luaL_checkstack (L , 1 , "in function mp_unpack_full" );
833
+
824
834
/* Return offset -1 when we have have processed the entire buffer. */
825
835
lua_pushinteger (L , c .left == 0 ? -1 : offset );
826
836
/* Results are returned with the arg elements still
0 commit comments