/* * nanowasm, a tiny WebAssembly/Wasm interpreter * Copyright (C) 2023-2024 Xavier Del Campo Romero * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include int check_resizable_limits(FILE *const f, struct resizable_limits *const r) { varuint1 flags; varuint32 initial; *r = (const struct resizable_limits){0}; if (varuint1_read(f, &flags)) { LOG("%s: varuint1_read failed\n", __func__); return -1; } else if (varuint32_read(f, &initial)) { LOG("%s: varuint32_read failed\n", __func__); return -1; } if (flags) { varuint32 maximum; if (varuint32_read(f, &maximum)) { LOG("%s: varuint32_read failed\n", __func__); return -1; } r->max = maximum; r->max_available = true; } static const unsigned long page_size = 64lu * 1024lu; if (initial > UINT32_MAX / page_size) { LOG("%s: initial size (%lu) overflow \n", __func__, (unsigned long)initial); return 1; } r->sz = initial * page_size; return 0; }