Bug 221428

Summary: WTF::dynamic_cf_cast<> should not assert in Debug builds
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: Web Template FrameworkAssignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=210729
https://bugs.webkit.org/show_bug.cgi?id=221521
https://bugs.webkit.org/show_bug.cgi?id=221767
Attachments:
Description Flags
Patch v1
ggaren: review+, ddkilzer: commit-queue-
Patch for landing
ews-feeder: commit-queue-
Patch for landing v2 none

Description David Kilzer (:ddkilzer) 2021-02-04 14:01:25 PST
WTF::dynamic_cf_cast<> should not assert in Debug builds.

The proper way to use dynamic_cf_cast<> is to do a nullptr check on its return results, and take action if the cast failed.  One of the most common use cases is when decoding (untrusted) serialized data, and instead of crashing, we just want to fail decoding on that particular chunk serialized data.

In some cases, we may way to add a nullptr check before calling it to differentiate that scenario from the wrong object type being detected.

We never want to use dynamic_cf_cast<> and assume it always succeeds, though.  In that case, we either want to use checked_cf_cast<> instead, or add a nullptr check to handle that scenario.

<rdar://problem/73451079>
Comment 1 David Kilzer (:ddkilzer) 2021-02-04 14:08:43 PST
Created attachment 419318 [details]
Patch v1
Comment 2 Geoffrey Garen 2021-02-04 14:13:14 PST
Comment on attachment 419318 [details]
Patch v1

r=me
Comment 3 David Kilzer (:ddkilzer) 2021-02-04 14:17:28 PST
Created attachment 419320 [details]
Patch for landing
Comment 4 David Kilzer (:ddkilzer) 2021-02-04 14:18:07 PST
Comment on attachment 419320 [details]
Patch for landing

Added comments about how to use each template function.
Comment 5 EWS 2021-02-04 15:00:17 PST
ChangeLog entry in Source/WTF/ChangeLog contains OOPS!.
Comment 6 David Kilzer (:ddkilzer) 2021-02-04 15:17:10 PST
Created attachment 419328 [details]
Patch for landing v2
Comment 7 EWS 2021-02-04 15:52:43 PST
Committed r272392: <https://trac.webkit.org/changeset/272392>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 419328 [details].