Skip to content

Comments

Fix size 65536 HybiFrames#24

Merged
GrahamCampbell merged 3 commits intochrome-php:1.7from
divinity76:fix-hybi-enc
May 1, 2025
Merged

Fix size 65536 HybiFrames#24
GrahamCampbell merged 3 commits intochrome-php:1.7from
divinity76:fix-hybi-enc

Conversation

@divinity76
Copy link

@divinity76 divinity76 commented May 1, 2025

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.2 wrong, 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

divinity76 added 2 commits May 1, 2025 09:17
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 divinity76 marked this pull request as ready for review May 1, 2025 07:22
| self::BITFIELD_FINAL
);

$masked_bit = (self::BITFIELD_MASKED & ($this->masked ? \PHP_INT_MAX : 0));
Copy link
Author

Choose a reason for hiding this comment

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

this was just unnecessarily complex / difficult to read.

// FIN + opcode byte
$this->buffer[self::BYTE_HEADER] = \chr(
(self::BITFIELD_TYPE & $this->type)
| (self::BITFIELD_FINAL & \PHP_INT_MAX)
Copy link
Author

@divinity76 divinity76 May 1, 2025

Choose a reason for hiding this comment

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

(non-negative-integer & \PHP_INT_MAX)
is a no-op 🤔 not sure what the original intention was.

@divinity76 divinity76 requested a review from GrahamCampbell May 1, 2025 11:05
@GrahamCampbell GrahamCampbell merged commit 2a542a8 into chrome-php:1.7 May 1, 2025
8 checks passed
@GrahamCampbell GrahamCampbell changed the title fix size 65536 HybiFrame + nitpicks Fix size 65536 HybiFrames May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants