diff --git a/src/spss/readstat_sav_read.c b/src/spss/readstat_sav_read.c index ab8ec9a..2b9ad19 100644 --- a/src/spss/readstat_sav_read.c +++ b/src/spss/readstat_sav_read.c @@ -598,6 +598,14 @@ static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) { if (ctx->bswap) var_count = byteswap4(var_count); + /* On wasm32 size_t is 32 bits: a damaged count of 0x40000001 made + * var_count * 4 wrap to 4, so a 4-byte block was read past its end + * for every count (a trap). johnmcm.com, Nov 2026. */ + if (var_count > SIZE_MAX / sizeof(uint32_t)) { + retval = READSTAT_ERROR_PARSE; + goto cleanup; + } + if (var_count && (vars = readstat_malloc(var_count * sizeof(uint32_t))) == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup;