Bug 281306
| Summary: | HashMap::get() / HashMap::take() return invalid ObjectIdentifiers when the key is missing | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Chris Dumez <cdumez> |
| Component: | Web Template Framework | Assignee: | Chris Dumez <cdumez> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Chris Dumez
An ObjectIdentifier cannot be invalid/empty, we normally use `std::optional<ObjectIdentifier>` or `Markable<ObjectIdentifier>` to represent an invalid/empty identifier. The only way to construct an "empty" ObjectIdentifier is via `HashTraits<ObjectIdentifier>::emptyValue()`, which HashMap relies on internally. As long as the HashMap is only using this special value internally, this is fine. However, HashMap::get() and HashMap::take() will return this invalid "empty" value if the key is not present. This was very error-prone for ObjectIdentifier since the client would receive an invalid ObjectIdentifier and have no way to check if the ObjectIdentifier is valid or not (since we assume an ObjectIdentifier is always valid).
To address the issue, we now forbid the use of HashMap::get() / HashMap::take() when the value type is an ObjectIdentifier and force the client to use `HashMap::getOptional()` / `HashMap::takeOptional()` instead, which returns a std::optional.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Chris Dumez
Pull request: https://github.com/WebKit/WebKit/pull/35043
Chris Dumez
Pull request: https://github.com/WebKit/WebKit/pull/35080
EWS
Committed 285080@main (263f7591998f): <https://commits.webkit.org/285080@main>
Reviewed commits have been landed. Closing PR #35080 and removing active labels.
Radar WebKit Bug Importer
<rdar://problem/137814913>