Patch for the heap out-of-bounds write described in #1153069.
`wvMergeCHPXFromBucket()` accumulates the merged grpprl length in a `U8`, so it wraps at
256, while the copy loop recomputes each sprm length into a wider `U16 i` and keeps
copying. The patch keeps the accumulator in `size_t`, allocates exactly that total, and
bounds the copy with a remaining-bytes counter. `dest->cbGrpprl` is still a `U8` in the
struct ABI, so the stored length is clamped to 0xff.
Tested on a plain/optimised build of 1.2.9 with the patch applied:
- merge-chpx-oob.doc: SIGSEGV before, rc=0 after
- merge-chpx-write-207.doc: "double free or corruption (out)" before, rc=0 after
- pchtabs-inbounds.doc and patched-pchtabs.doc: SEGV before, rc=0 after
- simple-bkd-len4.doc from #1153067: also rc=0, since this tree carries that fix too
- wv-corpus/backslash.doc: RTF output byte-identical before and after (1325 bytes)
Patch attached. It does not touch the Word 6 variant `wvMergeCHPXFromBucket6()`, which
still keeps a `U16` accumulator and did not overflow in these samples; keeping it out
makes the change minimal.
Happy to retest or rework the approach.
Patch for the heap out-of-bounds write described in #1153069.
`wvMergeCHPXFromBucket()` accumulates the merged grpprl length in a `U8`, so it wraps at
256, while the copy loop recomputes each sprm length into a wider `U16 i` and keeps
copying. The patch keeps the accumulator in `size_t`, allocates exactly that total, and
bounds the copy with a remaining-bytes counter. `dest->cbGrpprl` is still a `U8` in the
struct ABI, so the stored length is clamped to 0xff.
Tested on a plain/optimised build of 1.2.9 with the patch applied:
- merge-chpx-oob.doc: SIGSEGV before, rc=0 after
- merge-chpx-write-207.doc: "double free or corruption (out)" before, rc=0 after
- pchtabs-inbounds.doc and patched-pchtabs.doc: SEGV before, rc=0 after
- simple-bkd-len4.doc from #1153067: also rc=0, since this tree carries that fix too
- wv-corpus/backslash.doc: RTF output byte-identical before and after (1325 bytes)
Patch attached. It does not touch the Word 6 variant `wvMergeCHPXFromBucket6()`, which
still keeps a `U16` accumulator and did not overflow in these samples; keeping it out
makes the change minimal.
Happy to retest or rework the approach.
Patch for the heap out-of-bounds write described in #1153069.
`wvMergeCHPXFromBucket()` accumulates the merged grpprl length in a `U8`, so it wraps at
256, while the copy loop recomputes each sprm length into a wider `U16 i` and keeps
copying. The patch keeps the accumulator in `size_t`, allocates exactly that total, and
bounds the copy with a remaining-bytes counter. `dest->cbGrpprl` is still a `U8` in the
struct ABI, so the stored length is clamped to 0xff.
Tested on a plain/optimised build of 1.2.9 with the patch applied:
Patch for the heap out-of-bounds write described in #1153069.
`wvMergeCHPXFromBucket()` accumulates the merged grpprl length in a `U8`, so it wraps at
256, while the copy loop recomputes each sprm length into a wider `U16 i` and keeps
copying. The patch keeps the accumulator in `size_t`, allocates exactly that total, and
bounds the copy with a remaining-bytes counter. `dest->cbGrpprl` is still a `U8` in the
struct ABI, so the stored length is clamped to 0xff.
Tested on a plain/optimised build of 1.2.9 with the patch applied:
- merge-chpx-oob.doc: SIGSEGV before, rc=0 after
- merge-chpx-write-207.doc: "double free or corruption (out)" before, rc=0 after
- pchtabs-inbounds.doc and patched-pchtabs.doc: SEGV before, rc=0 after
- simple-bkd-len4.doc from #1153067: also rc=0, since this tree carries that fix too
- wv-corpus/backslash.doc: RTF output byte-identical before and after (1325 bytes)
Patch attached. It does not touch the Word 6 variant `wvMergeCHPXFromBucket6()`, which
still keeps a `U16` accumulator and did not overflow in these samples; keeping it out
makes the change minimal.
Happy to retest or rework the approach.
- merge-chpx-oob.doc: SIGSEGV before, rc=0 after
- merge-chpx-write-207.doc: "double free or corruption (out)" before, rc=0 after
- pchtabs-inbounds.doc and patched-pchtabs.doc: SEGV before, rc=0 after
- simple-bkd-len4.doc from #1153067: also rc=0, since this tree carries that fix too
- wv-corpus/backslash.doc: RTF output byte-identical before and after (1325 bytes)
Patch attached. It does not touch the Word 6 variant `wvMergeCHPXFromBucket6()`, which
still keeps a `U16` accumulator and did not overflow in these samples; keeping it out
makes the change minimal.
Happy to retest or rework the approach.