Bug 211000 - IPC::Decoder::isInvalid() should be renamed to isValid()
Summary: IPC::Decoder::isInvalid() should be renamed to isValid()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-04-24 15:29 PDT by David Kilzer (:ddkilzer)
Modified: 2020-04-28 15:50 PDT (History)
4 users (show)

See Also:


Attachments
Patch v1 (5.87 KB, patch)
2020-04-24 15:32 PDT, David Kilzer (:ddkilzer)
ddkilzer: commit-queue-
Details | Formatted Diff | Diff
Patch v2 (7.24 KB, patch)
2020-04-24 17:23 PDT, David Kilzer (:ddkilzer)
darin: review+
Details | Formatted Diff | Diff
Patch for landing (7.33 KB, patch)
2020-04-24 18:25 PDT, 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) 2020-04-24 15:29:34 PDT
IPC::Decoder::isInvalid() should be renamed to isValid().

Negative logic is more difficult to reason about.
Comment 1 David Kilzer (:ddkilzer) 2020-04-24 15:32:59 PDT
Created attachment 397519 [details]
Patch v1
Comment 2 David Kilzer (:ddkilzer) 2020-04-24 15:39:27 PDT
Comment on attachment 397519 [details]
Patch v1

Apparently there is usage of isInvalid() in assert statements!
Comment 3 David Kilzer (:ddkilzer) 2020-04-24 17:23:44 PDT
Created attachment 397529 [details]
Patch v2
Comment 4 Darin Adler 2020-04-24 17:41:40 PDT
Comment on attachment 397529 [details]
Patch v2

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

> Source/WebKit/ChangeLog:3
> +        IPC::Decoder::isInvalid() should be renamed to isValid()

You don’t say why

> Source/WebKit/Platform/IPC/Decoder.h:79
> -    bool isInvalid() const
> +    bool isValid() const
>      {
>          // (m_bufferPos == m_bufferEnd) is a valid state for decoding if the last parameter
>          // is a variable length byte array and its size == 0.
> -        return m_bufferPos < m_buffer || m_bufferPos > m_bufferEnd;
> +        return m_bufferPos >= m_buffer && m_bufferPos <= m_bufferEnd;
>      }

This is a very peculiar function. Why isn’t it just a null check? If we run off the end of the buffer, the damage has been done. Returning false from isValid doesn’t seem to do much good.
Comment 5 David Kilzer (:ddkilzer) 2020-04-24 18:16:59 PDT
Comment on attachment 397529 [details]
Patch v2

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

>> Source/WebKit/ChangeLog:3
>> +        IPC::Decoder::isInvalid() should be renamed to isValid()
> 
> You don’t say why

I'll add this to the ChangeLog (see Comment #0):

Negative logic is more difficult to reason about.

>> Source/WebKit/Platform/IPC/Decoder.h:79
>>      }
> 
> This is a very peculiar function. Why isn’t it just a null check? If we run off the end of the buffer, the damage has been done. Returning false from isValid doesn’t seem to do much good.

Tracking this issue in Bug 211006.
Comment 6 David Kilzer (:ddkilzer) 2020-04-24 18:25:04 PDT
Created attachment 397533 [details]
Patch for landing
Comment 7 EWS 2020-04-25 08:46:52 PDT
Committed r260704: <https://trac.webkit.org/changeset/260704>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 397533 [details].
Comment 8 Radar WebKit Bug Importer 2020-04-25 08:47:12 PDT
<rdar://problem/62371804>