fix(serde): raise catchable InvalidInputException instead of internal Buffer overflow on truncated/empty WKB (#866) - #867
Merged
Maxxen merged 1 commit intoSep 10, 2026
Conversation
…erflow on truncated/empty WKB (duckdb#866)
Member
|
Thanks! We should probably just fix |
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 #866
In column context, passing a 0-length blob (
''::BLOB) throughST_GeomFromWKB(w)returns an empty 0-byte geometry blob without failing early. When subsequent vector functions (e.g.ST_GeometryType,ST_IsEmpty,ST_Dimension,ST_NPoints,ST_X,ST_Force2D) deserialize the geometry,BinaryReader::CheckSizethrows an uncatchableINTERNAL Error: Buffer overflowassertion:Because an
InternalExceptionrepresents an assertion failure within DuckDB rather than user input error, it cannot be caught via SQLTRY()and immediately aborts the query and invalidates the client connection. Furthermore,ST_AsTexton the identical input raises a standard, catchable error:Root Cause
src/spatial/util/binary_reader.hpp,BinaryReader::CheckSizethrewInternalException("Buffer overflow")whenptr + size > end. A buffer underrun while reading deserialized geometry data is an invalid/truncated input condition, not an internal database assertion failure.src/spatial/geometry/geometry_serialization.cpp,DeserializeInternalhad no guard for empty buffers (buffer_size == 0), immediately triggeringCheckSize(sizeof(uint8_t))at offset 0.Changes
src/spatial/util/binary_reader.hpp:BinaryReader::CheckSizeto comparesize > static_cast<size_t>(end - ptr)(preventing integer overflow on malicious sizes) and throw:BlobReader.src/spatial/geometry/geometry_serialization.cpp:DeserializeInternalforbuffer_size == 0to immediately raiseInvalidInputException("Unexpected end of binary data at position 0").test/sql/geometry/st_geomfromwkb.test:Invalid Input Error: Unexpected end of binary data at position 0acrossST_GeometryType,ST_IsEmpty,ST_Dimension,ST_NPoints, andST_X.TRY(ST_GeometryType(...))andTRY(ST_IsEmpty(...))catch the error and cleanly returnNULL.