3 Commits

Author SHA1 Message Date
Bright Chen c9778ca1a3 Refactor NULL with nullptr in test (#3464) 2026-08-19 13:26:18 +08:00
Weibing Wang 96ce9f11ee Fix bug when parsing zero-length string field in mcpack2pb (#3450)
* Fix bug when parsing zero-length string field in mcpack2pb

UnparsedValue::as_string() resizes the output string to
without checking , where  is the value_size of a string
field read from the input. When value_size is 0,  underflows
to SIZE_MAX and resize() throws std::length_error, which is not caught
on the request path and therefore crashes the server. Reject such
malformed fields by marking the stream bad so the caller can fail the
request gracefully instead.

* Clear output string when size error
2026-08-16 18:01:01 +08:00
Weibing Wang 437a7b705c Limit mcpack2pb array item count to the actual payload size (#3451)
* Limit mcpack2pb array item count to the actual payload size

The item count in an mcpack array header is read directly from the
request and was used as-is by the generated parsing code to Reserve()
memory for repeated protobuf fields. A malformed request could claim an
item count up to INT32_MAX and force the server to preallocate ~16GB of
virtual memory, which may abort the process on memory-constrained hosts.

Cap the item count by the remaining bytes of the array (each item
occupies at least one byte) so that the preallocation is bounded by the
request size.

* Fix underflow in mcpack2pb array item count clamping
2026-08-16 01:06:46 +08:00