Bug 225335

Summary: Add bounds checks around calls to GlyphBuffer::stringOffsetAt()
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: cgarcia, ggaren, lmoura, simon.fraser, 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=225642
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
simon.fraser: review+
Patch for committing
ews-feeder: commit-queue-
Patch for committing none

Myles C. Maxfield
Reported 2021-05-03 16:36:04 PDT
Add bounds checks around calls to GlyphBuffer::stringOffsetAt()
Attachments
Patch (2.63 KB, patch)
2021-05-03 17:07 PDT, Myles C. Maxfield
ews-feeder: commit-queue-
Patch (2.67 KB, patch)
2021-05-03 17:11 PDT, Myles C. Maxfield
simon.fraser: review+
Patch for committing (6.81 KB, patch)
2021-05-08 15:47 PDT, Myles C. Maxfield
ews-feeder: commit-queue-
Patch for committing (6.83 KB, patch)
2021-05-08 15:52 PDT, Myles C. Maxfield
no flags
Myles C. Maxfield
Comment 1 2021-05-03 17:07:08 PDT
Myles C. Maxfield
Comment 2 2021-05-03 17:07:38 PDT
Myles C. Maxfield
Comment 3 2021-05-03 17:11:48 PDT
Geoffrey Garen
Comment 4 2021-05-03 18:54:46 PDT
r=me too
Geoffrey Garen
Comment 5 2021-05-03 19:01:54 PDT
Comment on attachment 427624 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=427624&action=review > Source/WebCore/platform/graphics/WidthIterator.cpp:398 > auto stringOffset = glyphBuffer.stringOffsetAt(i); Given the observation that stringOffsetAt may return an invalid value, indicating that CoreText did not find the string offset we wanted: (1) Can we just check for kCFNotFound (i.e., -1); that would be a lot more direct and clear. Do we benefit from this more abstract comparison here, and do we expect CoreText to return whacky values other than kCFNotFound for some reason? (2) Can stringOffsetAt return an Optional<GlyphBufferStringOffset> in order to become self-documenting? I don't think these questions block landing; but would be good to address.
Myles C. Maxfield
Comment 6 2021-05-08 15:24:47 PDT
Comment on attachment 427624 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=427624&action=review >> Source/WebCore/platform/graphics/WidthIterator.cpp:398 >> auto stringOffset = glyphBuffer.stringOffsetAt(i); > > Given the observation that stringOffsetAt may return an invalid value, indicating that CoreText did not find the string offset we wanted: > > (1) Can we just check for kCFNotFound (i.e., -1); that would be a lot more direct and clear. Do we benefit from this more abstract comparison here, and do we expect CoreText to return whacky values other than kCFNotFound for some reason? > > (2) Can stringOffsetAt return an Optional<GlyphBufferStringOffset> in order to become self-documenting? > > I don't think these questions block landing; but would be good to address. (1) Given that these values can come from another framework, I think we should be defensive. (2) It can! Good idea.
Myles C. Maxfield
Comment 7 2021-05-08 15:47:41 PDT
Created attachment 428094 [details] Patch for committing
Myles C. Maxfield
Comment 8 2021-05-08 15:52:47 PDT
Created attachment 428095 [details] Patch for committing
EWS
Comment 9 2021-05-08 17:14:09 PDT
Committed r277232 (237501@main): <https://commits.webkit.org/237501@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 428095 [details].
Lauro Moura
Comment 10 2021-05-09 17:42:14 PDT
Comment on attachment 428095 [details] Patch for committing View in context: https://bugs.webkit.org/attachment.cgi?id=428095&action=review > Source/WebCore/platform/graphics/GlyphBuffer.h:81 > + if (result < 0 || static_cast<unsigned>(result) >= stringLength) This is raising -Wtype-limits warnings on non-CG platforms due to GlyphBufferStringOffset being 'unsigned' there. What would be the proper way to silence them? Maybe move the result<0 comparison to a USE(CG) block? Example: In file included from WebCore/PrivateHeaders/WebCore/Font.h:30, from WebCore/PrivateHeaders/WebCore/FontCascade.h:28, from WebCore/PrivateHeaders/WebCore/GraphicsContext.h:32, from WebCore/PrivateHeaders/WebCore/FrameView.h:31, from ../../Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp:56: WebCore/PrivateHeaders/WebCore/GlyphBuffer.h: In member function ‘WTF::Optional<unsigned int> WebCore::GlyphBuffer::checkedStringOffsetAt(unsigned int, unsigned int) const’: WebCore/PrivateHeaders/WebCore/GlyphBuffer.h:81:20: warning: comparison of unsigned expression in ‘< 0’ is always false [-Wtype-limits] 81 | if (result < 0 || static_cast<unsigned>(result) >= stringLength) |
Note You need to log in before you can comment on or make changes to this bug.