fix: improve geography/geometry parser robustness#1843
Open
dhensby wants to merge 1 commit intotediousjs:masterfrom
Open
fix: improve geography/geometry parser robustness#1843dhensby wants to merge 1 commit intotediousjs:masterfrom
dhensby wants to merge 1 commit intotediousjs:masterfrom
Conversation
- Fix H flag check (IsLargerThanAHemisphere) using correct bit 5 instead of bit 3 which collided with P flag - Add bounds checking (ensureBytes) before all buffer reads to throw clear errors on truncated/corrupt spatial data instead of cryptic RangeErrors - Fix segment count check to require 4 bytes available instead of 1 Fixes tediousjs#322 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three bugs in the geography/geometry binary parser (
lib/udt.js) that caused crashes on certain spatial data inputs.Bugs Fixed
H flag (IsLargerThanAHemisphere) collision with P flag — The H flag was checked against bit 3 (
1 << 3), which is the same bit as the P (single point) flag. This meant v2 geography data with the H flag set would be incorrectly parsed as a single point. Fixed to use the correct bit 5 (1 << 5).No bounds checking on buffer reads — The parser performed no validation that sufficient data remained in the buffer before reading. Truncated or corrupt spatial data would produce cryptic
RangeError: Attempt to access memory outside buffer boundserrors. Added anensureBytes()helper that throws a clear'Spatial data is truncated'error before every read section.Segment count check off-by-one — The check for whether segments existed used
buffer.position < buffer.length, which would allow 1-3 trailing bytes to trigger a 4-byte read that overflows the buffer. Fixed tobuffer.position + 4 <= buffer.length.Tests Added
16 new unit tests covering:
Fixes #322