RESOLVED FIXED281306
HashMap::get() / HashMap::take() return invalid ObjectIdentifiers when the key is missing
https://bugs.webkit.org/show_bug.cgi?id=281306
Summary HashMap::get() / HashMap::take() return invalid ObjectIdentifiers when the ke...
Chris Dumez
Reported 2024-10-11 08:00:24 PDT
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
Chris Dumez
Comment 1 2024-10-11 08:14:34 PDT
Chris Dumez
Comment 2 2024-10-11 17:04:16 PDT
EWS
Comment 3 2024-10-12 14:36:26 PDT
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
Comment 4 2024-10-12 14:37:15 PDT
Note You need to log in before you can comment on or make changes to this bug.