Skip to content

fix: bound the size a compressed payload may expand to (#3502) - #3527

Merged
pjfanning merged 1 commit into
apache:1.7.xfrom
pjfanning:limit17
Sep 4, 2026
Merged

fix: bound the size a compressed payload may expand to (#3502)#3527
pjfanning merged 1 commit into
apache:1.7.xfrom
pjfanning:limit17

Conversation

@pjfanning

Copy link
Copy Markdown
Member

cherry pick #3502

Motivation:
Five serializers gzip their payload and decompress it on the way back in, each with the same unbounded loop: read the whole GZIPInputStream into a ByteArrayOutputStream. gzip expands by up to about three orders of magnitude, so neither the size of the compressed bytes nor the transport's frame limit bounds the buffer the decompressed bytes are read into.

Modification:
Add Decompression (@internalapi) with a gunzip that stops once the decompressed size passes pekko.serialization.max-decompressed-size (default 256 MiB) and reports it as a NotSerializableException, and route all twelve call sites through it. The Jackson serializers already bound decompression and keep their own
pekko.serialization.jackson.compression.max-decompressed-size.

Result:
An over-expanding payload is rejected as an ordinary serialization failure. No behaviour change for payloads within the limit.

  • change the default max-decompressed-size to unlimited

Motivation:
A bounded default could reject a payload an existing cluster legitimately exchanges, so a patch release carrying a 256 MiB default could break running clusters on upgrade. The bound should be opt-in.

Modification:
Default pekko.serialization.max-decompressed-size to -1, meaning no limit and matching the behaviour of earlier releases. A negative maximum skips the size check in gunzip. Config's getBytes refuses negative numbers, so the setting is read as a plain long first and as a memory size only when that is not a negative number.

Result:
Decompression is unbounded by default; configuring a size such as 256 MiB bounds it.

Tests:

  • sbt "actor-tests/testOnly org.apache.pekko.serialization.DecompressionSpec" - 8 passed
  • sbt "cluster/testOnly org.apache.pekko.cluster.protobuf.ClusterMessageSerializerDecompressionSpec" - 4 passed
  • sbt "distributed-data/testOnly org.apache.pekko.cluster.ddata.protobuf.SerializationSupportDecompressionSpec" - 3 passed
  • sbt "actor/scalafmtCheckAll" "actor-tests/scalafmtCheckAll" - clean

References:
Refs #3502

  • also accept "unlimited" for max-decompressed-size

Motivation:
Review on #3515 noted that an explicit keyword is clearer than a magic number. Keep the two sibling settings consistent: accept both spellings here as well.

Modification:
pekko.serialization.max-decompressed-size reads "unlimited" or any negative number as no limit; the reference.conf default is written as unlimited. New tests cover the keyword default and an explicit -1.

Result:
max-decompressed-size = unlimited and = -1 both disable the bound.

Tests:

  • sbt "actor-tests/testOnly org.apache.pekko.serialization.DecompressionSpec" - 9 passed
  • sbt "actor/scalafmtCheckAll" "actor-tests/scalafmtCheckAll" - clean

References:
Refs #3515, Refs #3502

* fix: bound the size a compressed payload may expand to

Motivation:
Five serializers gzip their payload and decompress it on the way back in,
each with the same unbounded loop: read the whole GZIPInputStream into a
ByteArrayOutputStream. gzip expands by up to about three orders of
magnitude, so neither the size of the compressed bytes nor the transport's
frame limit bounds the buffer the decompressed bytes are read into.

Modification:
Add Decompression (@internalapi) with a gunzip that stops once the
decompressed size passes pekko.serialization.max-decompressed-size
(default 256 MiB) and reports it as a NotSerializableException, and route
all twelve call sites through it. The Jackson serializers already bound
decompression and keep their own
pekko.serialization.jackson.compression.max-decompressed-size.

Result:
An over-expanding payload is rejected as an ordinary serialization
failure. No behaviour change for payloads within the limit.

* change the default max-decompressed-size to unlimited

Motivation:
A bounded default could reject a payload an existing cluster legitimately
exchanges, so a patch release carrying a 256 MiB default could break
running clusters on upgrade. The bound should be opt-in.

Modification:
Default pekko.serialization.max-decompressed-size to -1, meaning no limit
and matching the behaviour of earlier releases. A negative maximum skips
the size check in gunzip. Config's getBytes refuses negative numbers, so
the setting is read as a plain long first and as a memory size only when
that is not a negative number.

Result:
Decompression is unbounded by default; configuring a size such as 256 MiB
bounds it.

Tests:
- sbt "actor-tests/testOnly org.apache.pekko.serialization.DecompressionSpec" - 8 passed
- sbt "cluster/testOnly org.apache.pekko.cluster.protobuf.ClusterMessageSerializerDecompressionSpec" - 4 passed
- sbt "distributed-data/testOnly org.apache.pekko.cluster.ddata.protobuf.SerializationSupportDecompressionSpec" - 3 passed
- sbt "actor/scalafmtCheckAll" "actor-tests/scalafmtCheckAll" - clean

References:
Refs apache#3502

* also accept "unlimited" for max-decompressed-size

Motivation:
Review on apache#3515 noted that an explicit keyword is clearer than a magic
number. Keep the two sibling settings consistent: accept both spellings
here as well.

Modification:
pekko.serialization.max-decompressed-size reads "unlimited" or any
negative number as no limit; the reference.conf default is written as
`unlimited`. New tests cover the keyword default and an explicit -1.

Result:
`max-decompressed-size = unlimited` and `= -1` both disable the bound.

Tests:
- sbt "actor-tests/testOnly org.apache.pekko.serialization.DecompressionSpec" - 9 passed
- sbt "actor/scalafmtCheckAll" "actor-tests/scalafmtCheckAll" - clean

References:
Refs apache#3515, Refs apache#3502
@pjfanning pjfanning added this to the 1.7.1 milestone Sep 4, 2026
@pjfanning
pjfanning merged commit 08d5b70 into apache:1.7.x Sep 4, 2026
10 checks passed
@pjfanning
pjfanning deleted the limit17 branch September 4, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants