Skip to content

Commit 66cd7f6

Browse files
committed
Merge branch 'main' into fix/overflow
2 parents fd5cfe4 + 745da82 commit 66cd7f6

File tree

16 files changed

+89
-68
lines changed

16 files changed

+89
-68
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL
56-
uses: github/codeql-action/init@v3.28.19
56+
uses: github/codeql-action/init@v3.29.0
5757
with:
5858
languages: ${{ matrix.language }}
5959

@@ -70,7 +70,7 @@ jobs:
7070
- run: |
7171
./.github/scripts/codeql_buildscript.sh
7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@v3.28.19
73+
uses: github/codeql-action/analyze@v3.29.0
7474
with:
7575
category: "/language:${{matrix.language}}"
7676
upload: false
@@ -99,7 +99,7 @@ jobs:
9999
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
100100

101101
- name: Upload CodeQL results to code scanning
102-
uses: github/codeql-action/upload-sarif@v3.28.19
102+
uses: github/codeql-action/upload-sarif@v3.29.0
103103
with:
104104
sarif_file: ${{ steps.step1.outputs.sarif-output }}
105105
category: "/language:${{matrix.language}}"

.github/workflows/supply_chain.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ jobs:
6060

6161
# Upload the results to GitHub's code scanning dashboard.
6262
- name: "Upload to code-scanning"
63-
uses: github/codeql-action/upload-sarif@b1e4dc3db58c9601794e22a9f6d28d45461b9dbf
63+
uses: github/codeql-action/upload-sarif@2847b7f7ab9f48fc49eca90a53fff6007285f399
6464
with:
6565
sarif_file: results.sarif

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@
497497
- wasm loader: Fix handling if block without op else (#3404)
498498
- ref-types: Correct default value for function local variables (#3397)
499499
- aot compiler: Fix the length type passed to aot_memmove/aot_memset (#3378)
500-
- Fix loader and mini-loader select potiential error (#3374)
500+
- Fix loader and mini-loader select potential error (#3374)
501501
- Fix aot debugger compilation error on windows (#3370)
502502
- A few native stack detection fixes for macOS/arm64 (#3368)
503503
- Fix ESP32-S3 compiling error (#3359)

core/iwasm/aot/aot_loader.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,13 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
13091309
read_uint32(buf, buf_end, type_idx);
13101310
read_uint32(buf, buf_end, length);
13111311

1312+
if (type_idx >= module->type_count
1313+
|| !wasm_type_is_array_type(module->types[type_idx])) {
1314+
set_error_buf(error_buf, error_buf_size,
1315+
"invalid or non-array type index.");
1316+
goto fail;
1317+
}
1318+
13121319
if (init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT) {
13131320
expr->u.array_new_default.type_index = type_idx;
13141321
expr->u.array_new_default.length = length;

core/iwasm/common/gc/gc_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ wasm_reftype_is_subtype_of(uint8 type1, const WASMRefType *ref_type1,
11451145
return true;
11461146
else {
11471147
int32 heap_type = ref_type1->ref_ht_common.heap_type;
1148-
// We dont care whether type2 is nullable or not. So
1148+
// We don't care whether type2 is nullable or not. So
11491149
// we normalize it into its related one-byte type.
11501150
if (type2 == REF_TYPE_HT_NULLABLE
11511151
|| type2 == REF_TYPE_HT_NON_NULLABLE) {

core/iwasm/interpreter/wasm_loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
37283728
* we shall make a copy of code body [p_code, p_code + code_size]
37293729
* when we are worrying about inappropriate releasing behaviour.
37303730
* all code bodies are actually in a buffer which user allocates in
3731-
* his embedding environment and we don't have power on them.
3731+
* their embedding environment and we don't have power over them.
37323732
* it will be like:
37333733
* code_body_cp = malloc(code_size);
37343734
* memcpy(code_body_cp, p_code, code_size);

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
12261226
* we shall make a copy of code body [p_code, p_code + code_size]
12271227
* when we are worrying about inappropriate releasing behaviour.
12281228
* all code bodies are actually in a buffer which user allocates in
1229-
* his embedding environment and we don't have power on them.
1229+
* their embedding environment and we don't have power over them.
12301230
* it will be like:
12311231
* code_body_cp = malloc(code_size);
12321232
* memcpy(code_body_cp, p_code, code_size);

core/iwasm/libraries/debug-engine/debug_engine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance, uint64 offset,
743743
module_inst = (WASMModuleInstance *)exec_env->module_inst;
744744

745745
if (offset + *size > module_inst->module->load_size) {
746-
LOG_VERBOSE("wasm_debug_instance_get_data_mem size over flow!\n");
746+
LOG_VERBOSE("wasm_debug_instance_get_data_mem size overflow!\n");
747747
*size = module_inst->module->load_size >= offset
748748
? module_inst->module->load_size - offset
749749
: 0;
@@ -797,7 +797,7 @@ wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance, uint64 offset,
797797
num_bytes_per_page = memory->num_bytes_per_page;
798798
linear_mem_size = num_bytes_per_page * memory->cur_page_count;
799799
if (offset + *size > linear_mem_size) {
800-
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size over flow!\n");
800+
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size overflow!\n");
801801
*size = linear_mem_size >= offset ? linear_mem_size - offset : 0;
802802
}
803803
bh_memcpy_s(buf, (uint32)*size, memory->memory_data + offset,
@@ -830,7 +830,7 @@ wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance, uint64 offset,
830830
num_bytes_per_page = memory->num_bytes_per_page;
831831
linear_mem_size = num_bytes_per_page * memory->cur_page_count;
832832
if (offset + *size > linear_mem_size) {
833-
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size over flow!\n");
833+
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size overflow!\n");
834834
*size = linear_mem_size >= offset ? linear_mem_size - offset : 0;
835835
}
836836
bh_memcpy_s(memory->memory_data + offset, (uint32)*size, buf,

core/iwasm/libraries/wasi-nn/src/wasi_nn.c

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,43 @@ detect_and_load_backend(graph_encoding backend_hint,
397397
return ret;
398398
}
399399

400+
static wasi_nn_error
401+
ensure_backend(wasm_module_inst_t instance, graph_encoding encoding,
402+
WASINNContext **wasi_nn_ctx_ptr)
403+
{
404+
wasi_nn_error res;
405+
406+
graph_encoding loaded_backend = autodetect;
407+
if (!detect_and_load_backend(encoding, &loaded_backend)) {
408+
res = invalid_encoding;
409+
NN_ERR_PRINTF("load backend failed");
410+
goto fail;
411+
}
412+
413+
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
414+
if (wasi_nn_ctx->is_backend_ctx_initialized) {
415+
if (wasi_nn_ctx->backend != loaded_backend) {
416+
res = unsupported_operation;
417+
goto fail;
418+
}
419+
}
420+
else {
421+
wasi_nn_ctx->backend = loaded_backend;
422+
423+
/* init() the backend */
424+
call_wasi_nn_func(wasi_nn_ctx->backend, init, res,
425+
&wasi_nn_ctx->backend_ctx);
426+
if (res != success)
427+
goto fail;
428+
429+
wasi_nn_ctx->is_backend_ctx_initialized = true;
430+
}
431+
*wasi_nn_ctx_ptr = wasi_nn_ctx;
432+
return success;
433+
fail:
434+
return res;
435+
}
436+
400437
/* WASI-NN implementation */
401438

402439
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
@@ -410,14 +447,15 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
410447
graph_encoding encoding, execution_target target, graph *g)
411448
#endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
412449
{
450+
wasi_nn_error res;
451+
413452
NN_DBG_PRINTF("[WASI NN] LOAD [encoding=%d, target=%d]...", encoding,
414453
target);
415454

416455
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
417456
if (!instance)
418457
return runtime_error;
419458

420-
wasi_nn_error res;
421459
graph_builder_array builder_native = { 0 };
422460
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
423461
if (success
@@ -438,19 +476,8 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder,
438476
goto fail;
439477
}
440478

441-
graph_encoding loaded_backend = autodetect;
442-
if (!detect_and_load_backend(encoding, &loaded_backend)) {
443-
res = invalid_encoding;
444-
NN_ERR_PRINTF("load backend failed");
445-
goto fail;
446-
}
447-
448-
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
449-
wasi_nn_ctx->backend = loaded_backend;
450-
451-
/* init() the backend */
452-
call_wasi_nn_func(wasi_nn_ctx->backend, init, res,
453-
&wasi_nn_ctx->backend_ctx);
479+
WASINNContext *wasi_nn_ctx;
480+
res = ensure_backend(instance, encoding, &wasi_nn_ctx);
454481
if (res != success)
455482
goto fail;
456483

@@ -473,6 +500,8 @@ wasi_nn_error
473500
wasi_nn_load_by_name(wasm_exec_env_t exec_env, char *name, uint32_t name_len,
474501
graph *g)
475502
{
503+
wasi_nn_error res;
504+
476505
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
477506
if (!instance) {
478507
return runtime_error;
@@ -496,19 +525,8 @@ wasi_nn_load_by_name(wasm_exec_env_t exec_env, char *name, uint32_t name_len,
496525

497526
NN_DBG_PRINTF("[WASI NN] LOAD_BY_NAME %s...", name);
498527

499-
graph_encoding loaded_backend = autodetect;
500-
if (!detect_and_load_backend(autodetect, &loaded_backend)) {
501-
NN_ERR_PRINTF("load backend failed");
502-
return invalid_encoding;
503-
}
504-
505-
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
506-
wasi_nn_ctx->backend = loaded_backend;
507-
508-
wasi_nn_error res;
509-
/* init() the backend */
510-
call_wasi_nn_func(wasi_nn_ctx->backend, init, res,
511-
&wasi_nn_ctx->backend_ctx);
528+
WASINNContext *wasi_nn_ctx;
529+
res = ensure_backend(instance, autodetect, &wasi_nn_ctx);
512530
if (res != success)
513531
return res;
514532

@@ -526,6 +544,8 @@ wasi_nn_load_by_name_with_config(wasm_exec_env_t exec_env, char *name,
526544
int32_t name_len, char *config,
527545
int32_t config_len, graph *g)
528546
{
547+
wasi_nn_error res;
548+
529549
wasm_module_inst_t instance = wasm_runtime_get_module_inst(exec_env);
530550
if (!instance) {
531551
return runtime_error;
@@ -554,19 +574,8 @@ wasi_nn_load_by_name_with_config(wasm_exec_env_t exec_env, char *name,
554574

555575
NN_DBG_PRINTF("[WASI NN] LOAD_BY_NAME_WITH_CONFIG %s %s...", name, config);
556576

557-
graph_encoding loaded_backend = autodetect;
558-
if (!detect_and_load_backend(autodetect, &loaded_backend)) {
559-
NN_ERR_PRINTF("load backend failed");
560-
return invalid_encoding;
561-
}
562-
563-
WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance);
564-
wasi_nn_ctx->backend = loaded_backend;
565-
566-
wasi_nn_error res;
567-
/* init() the backend */
568-
call_wasi_nn_func(wasi_nn_ctx->backend, init, res,
569-
&wasi_nn_ctx->backend_ctx);
577+
WASINNContext *wasi_nn_ctx;
578+
res = ensure_backend(instance, autodetect, &wasi_nn_ctx);
570579
if (res != success)
571580
return res;
572581

core/iwasm/libraries/wasi-nn/src/wasi_nn_openvino.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,6 @@ load(void *ctx, graph_builder_array *builder, graph_encoding encoding,
225225
graph_builder xml = builder->buf[0];
226226
graph_builder weight = builder->buf[1];
227227

228-
/* if xml is a String with a model in IR */
229-
if (!(xml.buf[xml.size] == '\0' && xml.buf[xml.size - 1] != '\0')) {
230-
NN_ERR_PRINTF("Invalid xml string.");
231-
return invalid_argument;
232-
}
233-
234228
/* transfer weight to an ov tensor */
235229
{
236230
ov_ctx->weight_data = os_malloc(weight.size);

core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "wasm_export.h"
1111

1212
typedef struct {
13+
bool is_backend_ctx_initialized;
1314
bool is_model_loaded;
1415
graph_encoding backend;
1516
void *backend_ctx;

core/shared/platform/esp-idf/espidf_platform.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,20 @@ openat(int fd, const char *pathname, int flags, ...)
201201
int ret;
202202
char dir_path[DIR_PATH_LEN];
203203
char *full_path;
204+
mode_t mode = 0;
205+
bool has_mode = false;
206+
207+
if (flags & O_CREAT) {
208+
va_list ap;
209+
va_start(ap, flags);
210+
mode = (mode_t)va_arg(ap, int);
211+
va_end(ap);
212+
has_mode = true;
213+
}
204214

205215
ret = fcntl(fd, F_GETPATH, dir_path);
206216
if (ret != 0) {
207-
errno = -EINVAL;
217+
errno = EINVAL;
208218
return -1;
209219
}
210220

@@ -214,7 +224,7 @@ openat(int fd, const char *pathname, int flags, ...)
214224
return -1;
215225
}
216226

217-
new_fd = open(full_path, flags);
227+
new_fd = has_mode ? open(full_path, flags, mode) : open(full_path, flags);
218228
free(full_path);
219229

220230
return new_fd;

language-bindings/python/wamr-api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Pre-requisites
88
#### Install requirements
9-
Before proceeding it is necessary to make sure your Python environment is correctly configured. To do ths open a terminal session in this directory and perfom the following:
9+
Before proceeding it is necessary to make sure your Python environment is correctly configured. To do this open a terminal session in this directory and perform the following:
1010

1111

1212
```shell

language-bindings/python/wasm-c-api/docs/design.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,12 @@ writable and needs to be copied into a ctype array.
353353

354354
#### variable arguments
355355

356-
A function with _variable arugments_ makes it hard to specify the required
356+
A function with _variable arguments_ makes it hard to specify the required
357357
argument types for the function prototype. It leaves us one way to call it
358358
directly without any arguments type checking.
359359

360360
```python
361-
libc.printf(b"Hello, an int %d, a float %f, a string %s\n", c_int(1), c_doulbe(3.14), "World!")
361+
libc.printf(b"Hello, an int %d, a float %f, a string %s\n", c_int(1), c_double(3.14), "World!")
362362
```
363363

364364
#### Use `c_bool` to represent `wasm_mutability_t `
@@ -373,7 +373,7 @@ libc.printf(b"Hello, an int %d, a float %f, a string %s\n", c_int(1), c_doulbe(3
373373

374374
### bindgen.py
375375

376-
`bindge.py` is a tool to create WAMR python binding automatically. `binding.py`
376+
`bindgen.py` is a tool to create WAMR python binding automatically. `binding.py`
377377
is generated. We should avoid modification on it. Additional helpers should go
378378
to `ffi.py`.
379379

product-mini/platforms/linux-sgx/enclave-sample/App/pal_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct wamr_pal_create_process_args {
7979
// Untrusted environment variable array pass to new process.
8080
//
8181
// The untrusted env vars to the command. And the last element of the array
82-
// must be NULL to indicate the length of array.
82+
// must be NULL to indicate the end of the array.
8383
//
8484
// Optional field.
8585
const char **env;

tests/unit/memory64/memory64_atomic_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class memory64_atomic_test_suite : public testing::TestWithParam<RunningMode>
6060
return false;
6161
}
6262

63-
void destory_exec_env()
63+
void destroy_exec_env()
6464
{
6565
wasm_runtime_destroy_exec_env(exec_env);
6666
wasm_runtime_deinstantiate(module_inst);
@@ -109,7 +109,7 @@ class memory64_atomic_test_suite : public testing::TestWithParam<RunningMode>
109109
virtual void TearDown()
110110
{
111111
if (cleanup) {
112-
destory_exec_env();
112+
destroy_exec_env();
113113
wasm_runtime_destroy();
114114
cleanup = false;
115115
}
@@ -339,8 +339,8 @@ TEST_P(memory64_atomic_test_suite, atomic_opcodes_i64_rmw_cmpxchg)
339339
PUT_I64_TO_ADDR(wasm_argv + 2, 0x100F0E0D0C0B0A09);
340340
// new
341341
PUT_I64_TO_ADDR(wasm_argv + 4, 0xdeadcafebeefdead);
342-
ASSERT_TRUE(wasm_runtime_call_wasm(exec_env, func_map["i64_atomic_rmw_cmpxchg"],
343-
6, wasm_argv));
342+
ASSERT_TRUE(wasm_runtime_call_wasm(
343+
exec_env, func_map["i64_atomic_rmw_cmpxchg"], 6, wasm_argv));
344344
i64 = 0x100F0E0D0C0B0A09;
345345
ASSERT_EQ(i64, GET_U64_FROM_ADDR(wasm_argv));
346346

0 commit comments

Comments
 (0)