#1153076 wv: heap out-of-bounds read in wvApplysprmPIstdPermute

Package:
wv
Source:
wv
Description:
Programs for accessing Microsoft Word documents
Submitter:
zwf zwf
Date:
2026-11-05 08:13:01 UTC
Severity:
normal
Tags:
#1153076#5
Date:
2026-11-05 07:57:11 UTC
From:
To:
Hello,

I am reporting a reproducible heap out-of-bounds read in Debian wv 1.2.9-9 and upstream wvWare.

`wvApplysprmPIstdPermute()` allocates a remap table of `(cch - 6) / 2` entries, fills exactly that many, then indexes it with `apap->istd - istdFirst` while validating the index only against `istdFirst` / `istdLast` from the same operand (sprm.c:1093, sprm.c:1101, sprm.c:1116-1119). Nothing compares the index with the number of entries actually read, so an operand declaring a wide `istdLast` with a short `cch` reads past the allocation, and `apap->istd` is taken from the out-of-bounds word and used afterwards as a style index.

Reproduction (deterministic, harness attached):

    gcc -g -O1 -fsanitize=address -I. $(pkg-config --cflags glib-2.0 gobject-2.0) poc-pistd-harness.c .libs/libwv.a -lgsf-1 -lxml2 -lz -o poc-pistd
    ./poc-pistd

It builds a zeroed PAP with `istd = 2` and an operand with `cch = 8` (one entry) and `istdLast = 0xffff`, so the applied index 1 is one past the 2-byte allocation:

    ERROR: AddressSanitizer: heap-buffer-overflow
    READ of size 2
        #0 wvApplysprmPIstdPermute sprm.c:1119
        #1 wvApplySprmFromBucket sprm.c:257
        #2 wvAddPAPXFromBucket6 pap.c:111
        #3 wvGenerateStyle stylesheet.c:517

The attached `cand2.doc` reaches the same read through `wvRTF` on Word 6 input.

Suggested fix bounds the index by the filled count, and is attached:

    U16 nistd = 0; nistd = (U16)((cch - 6) / 2); ... < nistd in the if

With the patch the harness returns cleanly (`istd=2`) and normal documents keep byte-identical RTF output.

This is distinct from CVE-2026-112055 (`wvGetPAPX_FKP` / `wvGetCHPX_FKP`), CVE-2026-112056 (`wvGetSTSH`) and Debian Bug #1148725 (`pap.c` list indices); none of them touches this function. Note the sample still crashes after the patch in `mapFont`/`strcasecmp` (wvRTF.c:114), a separate defect of the same file, not this read.

Confirmed impact is out-of-bounds heap read and process termination; code execution is not claimed.

Please assign a CVE if Debian considers this a vulnerability in the Debian package. I am happy to retest a patched build.

Thanks,
netwind
zwfnetwind@hotmail.com

#1153076#10
Date:
2026-11-05 08:03:16 UTC
From:
To:
The document that reaches this read through wvRTF, attached (the function-level harness is already on the report).
#1153076#15
Date:
2026-11-05 08:05:29 UTC
From:
To:
Reported upstream as well, with the same sample, harness and patch attached: https://github.com/opendocument-app/wvWare/issues/4
#1153076#20
Date:
2026-11-05 08:11:29 UTC
From:
To:
Reported upstream as well, with the same sample, harness and patch attached: https://github.com/opendocument-app/wvWare/issues/4