Bug 238475

Summary: UTF-8 handling in MediaFragmentURIParser::parseFragments() seems wrong
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, annevk, darin, eric.carlson, jer.noble, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#processing-name-value-components
See Also: https://bugs.webkit.org/show_bug.cgi?id=238408

Description Chris Dumez 2022-03-28 16:01:01 PDT
UTF-8 handling in MediaFragmentURIParser::parseFragments() seems wrong:

```
        //  b. Convert name and value to Unicode strings by interpreting them as UTF-8. If either
        //     name or value are not valid UTF-8 strings, then remove the name-value pair from the list.
        bool validUTF8 = false;
        if (!name.isEmpty() && !value.isEmpty()) {
            name = String { name.utf8(StrictConversion).data() };
            validUTF8 = !name.isEmpty();

            if (validUTF8) {
                value = String { value.utf8(StrictConversion).data() };
                validUTF8 = !value.isEmpty();
            }
        }
```

Note that `String { }` parses the input string as latin1, not UTF-8. So we're converting to UTF-8 and then back as latin1.
Comment 1 Chris Dumez 2022-03-28 16:15:43 PDT
imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/media_fragment_seek.html seems to be this only WPT test we have that exercises this logic, but doesn't actually seem to cover UTF-8 cases.
Comment 2 Chris Dumez 2022-03-28 16:23:55 PDT
(In reply to Chris Dumez from comment #1)
> imported/w3c/web-platform-tests/html/semantics/embedded-content/media-
> elements/media_fragment_seek.html seems to be this only WPT test we have
> that exercises this logic, but doesn't actually seem to cover UTF-8 cases.

Looks like there are quite a few related tests in media/media-fragments though.
Comment 3 Radar WebKit Bug Importer 2022-04-04 16:01:15 PDT
<rdar://problem/91266173>