flatbuffers/go
Ville Vesilehto 1e6c851dba
fix(go/grpc): avoid panic on short FlatBuffers input (#8684)
* fix(go/grpc): avoid panic on short FlatBuffers input

The gRPC codec read the root UOffsetT without checking input size. On
buffers shorter than SizeUOffsetT, GetUint32 touched data[3] and the
process panics.

Add a simple length check and validate the root offset stays within the
buffer. Return clear errors (insufficient data / invalid root offset)
instead of panicking.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* fix(go/grpc): avoid signed overflow in offset

Keep the bounds check in the unsigned domain (UOffsetT) to avoid
signedness pitfalls.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* chore: clarify comment regarding offset

A full FlatBuffer structure would be:

- uoffset_t: root table offset (4 bytes)
- soffset_t: vtable offset in root table (4 bytes)
- uint16_t: vtable size (2 bytes)
- uint16_t: table size (2 bytes)

In total 12 bytes. We are only validating the data length
before trying to read the uoffset_t, not the full structure.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

---------

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Co-authored-by: Derek Bailey <derekbailey@google.com>
2025-08-28 00:31:57 -07:00
..
BUILD.bazel
builder.go Add key lookup support for tables in Go (#7644) 2022-11-22 14:08:19 -08:00
doc.go
encode.go GetUOffsetT must get value by GetUint32 not GetInt32 (#6072) 2021-02-18 18:38:25 -08:00
grpc.go fix(go/grpc): avoid panic on short FlatBuffers input (#8684) 2025-08-28 00:31:57 -07:00
lib.go Support file_identifier in Go (#7904) 2023-04-26 05:15:09 +00:00
sizes.go
struct.go
table.go