Skip to content

Validate uncompressed size in OP_COMPRESSED messages - #2976

Open
dfengliu wants to merge 1 commit into
mongodb:mainfrom
dfengliu:fix/op-compressed-size-validation
Open

Validate uncompressed size in OP_COMPRESSED messages#2976
dfengliu wants to merge 1 commit into
mongodb:mainfrom
dfengliu:fix/op-compressed-size-validation

Conversation

@dfengliu

@dfengliu dfengliu commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Validate the uncompressed_size field from the OP_COMPRESSED wire protocol compression sub-header against max_message_size.

Details

The process_compression_header method in network_layer.py previously unpacked the compression sub-header and discarded the uncompressed_size field. A malicious or compromised MongoDB server could send a small compressed envelope (passing the envelope size check) that decompresses to a very large payload, causing memory exhaustion.

Changes

  • process_compression_header now returns uncompressed_size in addition to op_code and compressor_id
  • The caller validates uncompressed_size against self._max_message_size and raises ProtocolError if it exceeds the limit
  • Added unit test test_compression_uncompressed_size_exceeds_max_closes

The process_compression_header method previously discarded the
uncompressed_size field from the compression sub-header. A malicious
or compromised server could send a small compressed envelope
(passing the max_message_size check) that decompresses to a very
large payload, causing memory exhaustion.

This change returns the uncompressed_size from the compression header
and validates it against max_message_size before accepting the
compressed payload.
@dfengliu
dfengliu requested a review from a team as a code owner August 1, 2026 09:27
@dfengliu
dfengliu requested a review from blink1073 August 1, 2026 09:27
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.

1 participant