Bug 239057 - [WebGPU] WebGPU strings are UTF-8, not Latin-1
Summary: [WebGPU] WebGPU strings are UTF-8, not Latin-1
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGPU (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on: 239056
Blocks:
  Show dependency treegraph
 
Reported: 2022-04-10 18:33 PDT by Myles C. Maxfield
Modified: 2022-04-12 15:40 PDT (History)
5 users (show)

See Also:


Attachments
Patch (5.12 KB, patch)
2022-04-10 18:36 PDT, Myles C. Maxfield
kkinnunen: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2022-04-10 18:33:34 PDT
.
Comment 1 Myles C. Maxfield 2022-04-10 18:36:42 PDT
Created attachment 457219 [details]
Patch
Comment 2 Kimmo Kinnunen 2022-04-11 01:23:44 PDT
Comment on attachment 457219 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457219&action=review

> Source/WebGPU/WebGPU/Adapter.mm:137
> +    auto label = String::fromUTF8(descriptor.label);

Aren't these coming from the API? E.g. would fromAPI() be more appropriate?
Comment 3 Myles C. Maxfield 2022-04-11 17:34:23 PDT
Comment on attachment 457219 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457219&action=review

>> Source/WebGPU/WebGPU/Adapter.mm:137
>> +    auto label = String::fromUTF8(descriptor.label);
> 
> Aren't these coming from the API? E.g. would fromAPI() be more appropriate?

Good point.
Comment 4 Myles C. Maxfield 2022-04-11 17:40:39 PDT
Committed r292748 (?): <https://commits.webkit.org/r292748>
Comment 5 Radar WebKit Bug Importer 2022-04-11 17:41:16 PDT
<rdar://problem/91598857>
Comment 6 Darin Adler 2022-04-12 12:30:03 PDT
Comment on attachment 457219 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457219&action=review

> Source/WebGPU/ChangeLog:8
> +        Replace String::fromLatin1() with String::fromUTF8().

Great to fix this if it was going to mishandle non-ASCII characters. But note that now there is a failure case for all of these, if it’s invalid UTF-8. This is a major difference between String::fromUTF8 and String::fromLatin1, and might eventually lead to us renaming it to String::tryFromUTF8.

As long as each caller either has a guarantee it will be valid UTF-8, or can withstand a null string result when it’s not, we are OK.
Comment 7 Myles C. Maxfield 2022-04-12 15:40:49 PDT
Comment on attachment 457219 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457219&action=review

>> Source/WebGPU/ChangeLog:8
>> +        Replace String::fromLatin1() with String::fromUTF8().
> 
> Great to fix this if it was going to mishandle non-ASCII characters. But note that now there is a failure case for all of these, if it’s invalid UTF-8. This is a major difference between String::fromUTF8 and String::fromLatin1, and might eventually lead to us renaming it to String::tryFromUTF8.
> 
> As long as each caller either has a guarantee it will be valid UTF-8, or can withstand a null string result when it’s not, we are OK.

Right. For this situation, it's the latter.