Skip to content

Commit

Permalink
Fix WebVTT Parser to disallow negative percentages
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263640

Reviewed by Eric Carlson.

This patch addresses an issue in the WebVTT parser where it incorrectly
allowed negative percentage values for region and viewport anchors.
According to the WebVTT specification, percentage values must be in the
range of 0 to 100, and negative percentages are not valid. This patch
ensures that the parser correctly identifies negative percentages
as invalid values.

* LayoutTests/imported/w3c/web-platform-tests/webvtt/parsing/file-parsing/tests/regions-regionanchor-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/webvtt/parsing/file-parsing/tests/regions-viewportanchor-expected.txt:
* Source/WebCore/html/track/WebVTTParser.cpp:
(WebCore::WebVTTParser::parseFloatPercentageValue):

Canonical link: https://commits.webkit.org/269882@main
  • Loading branch information
cola119 authored and annevk committed Oct 28, 2023
1 parent 1776d35 commit 6c997a6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL regions, regionanchor assert_equals: Failed with region 13 expected 0 but got -0
PASS regions, regionanchor

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL regions, viewportanchor assert_equals: Failed with region 13 expected 0 but got -0
PASS regions, viewportanchor

5 changes: 3 additions & 2 deletions Source/WebCore/html/track/WebVTTParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ constexpr unsigned styleIdentifierLength = 5;
bool WebVTTParser::parseFloatPercentageValue(VTTScanner& valueScanner, float& percentage)
{
float number;
if (!valueScanner.scanFloat(number))
bool isNegative = false;
if (!valueScanner.scanFloat(number, &isNegative))
return false;
// '%' must be present and at the end of the setting value.
if (!valueScanner.scan('%'))
return false;

if (number < 0 || number > 100)
if (isNegative || number > 100)
return false;

percentage = number;
Expand Down

0 comments on commit 6c997a6

Please sign in to comment.