Fix size 65536 HybiFrames#24
Merged
GrahamCampbell merged 3 commits intochrome-php:1.7from May 1, 2025
Merged
Conversation
off-by-1: previously, hybiframes with a 65536 bytes payload
would generate a 16 bit size header signaling 0 bytes (pack("n", 65536) => "\x00\x00"),
instead of using a 64bit size header.
nit: composer.json php version had not been updated since 8.0.2
nit: instead of is_int && in_array, we can use in_array's strict mode.
nit: $this->offset_mask and $this->offset_payload were
initialized-to-null in constructor and encode, then written internally in getPayloadOffset,
then written in encode() again.
nit: use pack('J') instead of manually constructing big_endian_u64 (undocumented funfact, J is not available in 32bit php: php/doc-en#4644 ,
that may be why the original code did not use J)
nit: use random_bytes instead of openssl_random_pseudo_bytes(),
the original code was written for php5 where random_bytes did not exist.
nit: getInitialLength() was calculating the result twice internally.
divinity76
commented
May 1, 2025
| | self::BITFIELD_FINAL | ||
| ); | ||
|
|
||
| $masked_bit = (self::BITFIELD_MASKED & ($this->masked ? \PHP_INT_MAX : 0)); |
Author
There was a problem hiding this comment.
this was just unnecessarily complex / difficult to read.
divinity76
commented
May 1, 2025
| // FIN + opcode byte | ||
| $this->buffer[self::BYTE_HEADER] = \chr( | ||
| (self::BITFIELD_TYPE & $this->type) | ||
| | (self::BITFIELD_FINAL & \PHP_INT_MAX) |
Author
There was a problem hiding this comment.
(non-negative-integer & \PHP_INT_MAX)
is a no-op 🤔 not sure what the original intention was.
GrahamCampbell
requested changes
May 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
off-by-1: previously, hybiframes with a 65536 bytes payload would generate a 16 bit size header signaling 0 bytes (pack("n", 65536) => "\x00\x00"), instead of using a 64bit size header.
nit: instead of is_int && in_array, we can use in_array's strict mode.
nit: $this->offset_mask and $this->offset_payload were initialized-to-null in constructor and encode, then written internally in getPayloadOffset,
then written in encode() again.
nit: use pack('J') instead of manually constructing big_endian_u64 (undocumented funfact, J is not available in 32bit php: php/doc-en#4644 , that may be why the original code did not use J)
nit: getInitialLength() was calculating the result twice internally.
nit: composer.json php version had not been updated since 8.0.2wrong, my bad, reverted.nit: use random_bytes instead of openssl_random_pseudo_bytes(), the original code was written for php5 where random_bytes did not exist.moved to dedicated PR: #22