protobuf-go/internal
Damien Neil 37cbbeb558 internal/impl: check for size cache overflow
The size cache is an int32. Store a -1 in it if the message size
overflows, and fall back to recomputing the size if the value is
negative. This means lamentable O(N^2) costs in marshaling,
but that's better than silently producing invalid output.

Also considered: Return an error. Avoids O(N^2) behavior, but gives the
user no good choices if they don't care the output being slow. Encoding
costs of messages this large are likely to be dominated by copying the
bytes rather than the size operation anyway, so slow-but-correct seems
like the most generally useful option.

We could store valid values for the range (0x7fffffff,0xfffffffe)
reserving only 0xffffffff as the overflow sentinel, but optimizing this
case seems less important than the code being obviously correct.

Fixes golang/protobuf#970.

Change-Id: I44f59ff81fdfbc8672dd5aec959d5153a081aab9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/220593
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2020-02-24 20:12:47 +00:00
..
benchmarks all: fast-path method refactoring 2020-02-19 22:01:50 +00:00
cmd internal/cmd: print generated filename only when contents change 2020-02-21 17:59:52 +00:00
conformance encoding/prototext: rewrite of internal/encoding/text 2020-02-05 02:11:08 +00:00
descfmt
descopts
detrand
encoding all: remove stray "." from license headers 2020-02-20 18:54:38 +00:00
errors all: scrub all TODOs 2020-02-10 19:28:48 +00:00
fieldnum all: remove stray "." from license headers 2020-02-20 18:54:38 +00:00
fieldsort
filedesc all: remove stray "." from license headers 2020-02-20 18:54:38 +00:00
filetype
flags all: add a test for copyright headers 2020-02-21 18:41:46 +00:00
fuzz all: rename IsInitialized as CheckInitialized 2020-02-20 20:45:40 +00:00
fuzztest internal/fuzztest: set cap to len on test byte slice 2020-02-05 22:46:04 +00:00
genname internal/genname: centralize the definitions for generated names 2019-12-09 22:57:38 +00:00
impl internal/impl: check for size cache overflow 2020-02-24 20:12:47 +00:00
mapsort internal/testprotos/legacy: rename and regenerate 2020-01-12 08:13:18 +00:00
pragma all: add a test for copyright headers 2020-02-21 18:41:46 +00:00
protobuild proto: refactor merge tests 2020-02-12 19:41:50 +00:00
protolegacy all: add a test for copyright headers 2020-02-21 18:41:46 +00:00
set
strs
testprotos all: add a test for copyright headers 2020-02-21 18:41:46 +00:00
weakdeps internal/weakdeps: put APIv1 weak dependency behind a build constraint 2020-02-14 21:08:34 +00:00