Skip to content

Commit de13df1

Browse files
authored
CSS Processor: Fix consume_ident_start_codepoint bounds check (#219)
Fixes out-of-bounds string offset access when the input string ends while consuming an ident start.
1 parent 205a548 commit de13df1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

components/DataLiberation/CSS/class-cssprocessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ private function consume_ident_codepoint( $at ): int {
15001500
* @return int The number of bytes consumed.
15011501
*/
15021502
private function consume_ident_start_codepoint( $at ): int {
1503-
if ( $at > $this->length ) {
1503+
if ( $at >= $this->length ) {
15041504
return 0;
15051505
}
15061506

components/DataLiberation/Tests/CSSProcessorTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,5 +1530,15 @@ public function test_set_token_with_invalid_utf8_sequence(): void {
15301530
$this->assertSame( "background: url(\"\xC0.jpg\");", $updated );
15311531
}
15321532

1533-
1533+
/**
1534+
* Test bounds check when consuming and ident start token.
1535+
*/
1536+
public function test_ident_start_codepoint_bounds_check(): void {
1537+
$processor = CSSProcessor::create( '-' );
1538+
$actual_tokens = $this->collect_tokens( $processor, array( 'type', 'raw' ) );
1539+
$expected_tokens = array(
1540+
array( 'type' => CSSProcessor::TOKEN_DELIM, 'raw' => '-' ),
1541+
);
1542+
$this->assertSame( $expected_tokens, $actual_tokens );
1543+
}
15341544
}

0 commit comments

Comments
 (0)