Commit 4e25461
authored
### Rationale for this change
`WKBBuffer::ReadCoords()` computes the coordinate sequence byte size using `n_coords * sizeof(Coord)` before validating the remaining buffer size.
On 32-bit targets such as wasm32, this multiplication can overflow when `n_coords` is derived from malformed WKB input, causing the bounds check to validate a truncated value before the subsequent coordinate read loop processes the coordinate sequence.
This change widens the computation before validation so the bounds check remains correct across supported architectures.
Related issue: #50051
### What changes are included in this PR?
* Widen the coordinate sequence byte-size computation in `WKBBuffer::ReadCoords()`
* Prevent overflow-before-bounds-check behavior on 32-bit targets
* Audit and harden closely related WKB parsing size computations with the same externally controlled arithmetic pattern
### Are these changes tested?
Yes.
Added coverage for malformed WKB inputs that exercise overflow-sensitive coordinate size calculations and verified the parser rejects invalid input safely.
### Are there any user-facing changes?
No.
**This PR contains a "Critical Fix".**
Malformed WKB input could cause coordinate sequence size calculations to overflow on 32-bit targets before bounds validation occurs, potentially resulting in out-of-bounds reads during parsing.
This change ensures bounds validation uses widened arithmetic before parsing coordinate sequences.
* GitHub Issue: #50051
Authored-by: jmestwa-coder <jmestwa@gmail.com>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
1 parent 9265a71 commit 4e25461
2 files changed
Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
169 | 184 | | |
170 | 185 | | |
171 | 186 | | |
| |||
0 commit comments