@@ -665,7 +665,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
665665 const char * table_name , WASMTableImport * table ,
666666 char * error_buf , uint32 error_buf_size )
667667{
668- const uint8 * p = * p_buf , * p_end = buf_end ;
668+ const uint8 * p = * p_buf , * p_end = buf_end , * p_org ;
669669 uint32 declare_elem_type = 0 , table_flag = 0 , declare_init_size = 0 ,
670670 declare_max_size = 0 ;
671671
@@ -678,7 +678,12 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
678678#endif
679679 );
680680
681+ /* the table flag can't exceed one byte, only check in debug build given
682+ * the nature of mini-loader */
683+ p_org = p ;
681684 read_leb_uint32 (p , p_end , table_flag );
685+ bh_assert (p - p_org <= 1 );
686+ (void )p_org ;
682687
683688 if (!wasm_table_check_flags (table_flag , error_buf , error_buf_size , false)) {
684689 return false;
@@ -711,7 +716,7 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
711716 const char * memory_name , WASMMemoryImport * memory ,
712717 char * error_buf , uint32 error_buf_size )
713718{
714- const uint8 * p = * p_buf , * p_end = buf_end ;
719+ const uint8 * p = * p_buf , * p_end = buf_end , * p_org ;
715720#if WASM_ENABLE_APP_FRAMEWORK != 0
716721 uint32 pool_size = wasm_runtime_memory_pool_size ();
717722 uint32 max_page_count = pool_size * APP_MEMORY_MAX_GLOBAL_HEAP_PERCENT
@@ -724,7 +729,13 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end,
724729 uint32 declare_init_page_count = 0 ;
725730 uint32 declare_max_page_count = 0 ;
726731
732+ /* the memory flag can't exceed one byte, only check in debug build given
733+ * the nature of mini-loader */
734+ p_org = p ;
727735 read_leb_uint32 (p , p_end , mem_flag );
736+ bh_assert (p - p_org <= 1 );
737+ (void )p_org ;
738+
728739 if (!wasm_memory_check_flags (mem_flag , error_buf , error_buf_size , false)) {
729740 return false;
730741 }
@@ -815,6 +826,8 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMTable *table,
815826#endif
816827 );
817828
829+ /* the table flag can't exceed one byte, only check in debug build given
830+ * the nature of mini-loader */
818831 p_org = p ;
819832 read_leb_uint32 (p , p_end , table -> table_type .flags );
820833 bh_assert (p - p_org <= 1 );
@@ -854,6 +867,8 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory,
854867 bool is_memory64 = false;
855868#endif
856869
870+ /* the memory flag can't exceed one byte, only check in debug build given
871+ * the nature of mini-loader */
857872 p_org = p ;
858873 read_leb_uint32 (p , p_end , memory -> flags );
859874 bh_assert (p - p_org <= 1 );
0 commit comments