Bug 221428 - WTF::dynamic_cf_cast<> should not assert in Debug builds
Summary: WTF::dynamic_cf_cast<> should not assert in Debug builds
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-04 14:01 PST by David Kilzer (:ddkilzer)
Modified: 2021-02-11 11:53 PST (History)
3 users (show)

See Also:


Attachments
Patch v1 (1.22 KB, patch)
2021-02-04 14:08 PST, David Kilzer (:ddkilzer)
ggaren: review+
ddkilzer: commit-queue-
Details | Formatted Diff | Diff
Patch for landing (1.83 KB, patch)
2021-02-04 14:17 PST, David Kilzer (:ddkilzer)
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing v2 (1.82 KB, patch)
2021-02-04 15:17 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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].