Skip to content

handle BFINAL deflate blocks in permessage-deflate decoders - #942

Open
Hsnmohd wants to merge 1 commit into
apache:masterfrom
Hsnmohd:permessage-deflate-bfinal
Open

Hsnmohd wants to merge 1 commit into
apache:masterfrom
Hsnmohd:permessage-deflate-bfinal

Conversation

@Hsnmohd

@Hsnmohd Hsnmohd commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

stop inflating in PerMessageDeflateExtension.decode once the Inflater has finished and reset it there and in PerMessageDeflate, otherwise a frame ending in a BFINAL deflate block (RFC 7692 §7.2.3.4, e.g. the RFC's own 8-byte Hello example) spins the server read thread in an infinite loop and the client decodes every later message as empty.

PerMessageDeflateExtension.decode looped while the Inflater did not
need input. After a DEFLATE block with BFINAL set, which RFC 7692
section 7.2.3.4 allows, the Inflater is finished and returns 0 while
the trailing bytes stay unconsumed, so the loop never exits and a
single compressed frame pins the server thread. The client-side
PerMessageDeflate decoder did stop, but never reset the finished
Inflater, so later messages decoded to empty payloads.

Stop inflating once the stream is finished and reset the Inflater so
the next DEFLATE stream decodes.

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. The infinite loop is addressed, but I think there is still an issue.

RFC 7692 §7.2.1 allows multiple DEFLATE blocks in a single message, including BFINAL=1 followed by additional blocks. The current implementation resets the Inflater without processing the remaining input, potentially truncating the message.

Could you cover this case, including fragmented messages, with a regression test?

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