Closed Bug 961859 Opened 12 years ago Closed 12 years ago

Out of bounds read(4) in SelectionIterator::GetNextSegment

Categories

(Core :: Layout: Text and Fonts, defect)

x86_64
All
defect
Not set
critical

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: inferno, Assigned: inferno)

Details

(4 keywords, Whiteboard: [asan])

Attachments

(3 files)

Attached file Testcase —
==26182==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000843b0c at pc 0x7fb564210df5 bp 0x7fff16ace740 sp 0x7fff16ace738 READ of size 4 at 0x611000843b0c thread T0 #0 0x7fb564210df4 in SelectionIterator::GetNextSegment(double*, unsigned int*, unsigned int*, double*, short*, mozilla::TextRangeStyle*) objdir-ff-asan/layout/generic/../../dist/include/gfxFont.h:2172 #1 0x7fb5642169f3 in nsTextFrame::PaintTextSelectionDecorations(gfxContext*, gfxPoint const&, gfxPoint const&, gfxRect const&, PropertyProvider&, unsigned int, unsigned int, nsTextPaintStyle&, SelectionDetails*, short, nsTextFrame::DrawPathCallbacks*) layout/generic/nsTextFrame.cpp:5632 #2 0x7fb56421720c in nsTextFrame::PaintTextWithSelection(gfxContext*, gfxPoint const&, gfxPoint const&, gfxRect const&, PropertyProvider&, unsigned int, unsigned int, nsTextPaintStyle&, nsCharClipDisplayItem::ClipEdges const&, gfxTextContextPaint*, nsTextFrame::DrawPathCallbacks*) layout/generic/nsTextFrame.cpp:5688 #3 0x7fb564209ccf in nsTextFrame::PaintText(nsRenderingContext*, nsPoint, nsRect const&, nsCharClipDisplayItem const&, gfxTextContextPaint*, nsTextFrame::DrawPathCallbacks*) layout/generic/nsTextFrame.cpp:5913 #4 0x7fb564208adc in nsDisplayText::Paint(nsDisplayListBuilder*, nsRenderingContext*) layout/generic/nsTextFrame.cpp:4591 #5 0x7fb563eb6054 in mozilla::FrameLayerBuilder::PaintItems(nsTArray<mozilla::FrameLayerBuilder::ClippedDisplayItem>&, nsIntRect const&, gfxContext*, nsRenderingContext*, nsDisplayListBuilder*, nsPresContext*, nsIntPoint const&, float, float, int) layout/base/FrameLayerBuilder.cpp:3487 #6 0x7fb563eb833a in mozilla::FrameLayerBuilder::DrawThebesLayer(mozilla::layers::ThebesLayer*, gfxContext*, nsIntRegion const&, mozilla::layers::DrawRegionClip, nsIntRegion const&, void*) layout/base/FrameLayerBuilder.cpp:3649 #7 0x7fb5611b4f21 in mozilla::layers::BasicThebesLayer::PaintBuffer(gfxContext*, nsIntRegion const&, nsIntRegion const&, nsIntRegion const&, bool, mozilla::layers::DrawRegionClip, void (*)(mozilla::layers::ThebesLayer*, gfxContext*, nsIntRegion const&, mozilla::layers::DrawRegionClip, nsIntRegion const&, void*), void*) gfx/layers/basic/BasicThebesLayer.h:114 #8 0x7fb5611961b8 in mozilla::layers::BasicThebesLayer::Validate(void (*)(mozilla::layers::ThebesLayer*, gfxContext*, nsIntRegion const&, mozilla::layers::DrawRegionClip, nsIntRegion const&, void*), void*) gfx/layers/basic/BasicThebesLayer.cpp:202 #9 0x7fb5611893ad in non-virtual thunk to mozilla::layers::BasicContainerLayer::Validate(void (*)(mozilla::layers::ThebesLayer*, gfxContext*, nsIntRegion const&, mozilla::layers::DrawRegionClip, nsIntRegion const&, void*), void*) gfx/layers/basic/BasicContainerLayer.cpp:124 #10 0x7fb5611893ad in non-virtual thunk to mozilla::layers::BasicContainerLayer::Validate(void (*)(mozilla::layers::ThebesLayer*, gfxContext*, nsIntRegion const&, mozilla::layers::DrawRegionClip, nsIntRegion const&, void*), void*) gfx/layers/basic/BasicContainerLayer.cpp:124 #11 0x7fb56118c4d5 in mozilla::layers::BasicLayerManager::EndTransactionInternal(void (*)(mozilla::layers::ThebesLayer*, gfxContext*, nsIntRegion const&, mozilla::layers::DrawRegionClip, nsIntRegion const&, void*), void*, mozilla::layers::LayerManager::EndTransactionFlags) gfx/layers/basic/BasicLayerManager.cpp:597 #12 0x7fb563f92912 in nsDisplayList::PaintForFrame(nsDisplayListBuilder*, nsRenderingContext*, nsIFrame*, unsigned int) const layout/base/nsDisplayList.cpp:1231 #13 0x7fb563f91453 in nsDisplayList::PaintRoot(nsDisplayListBuilder*, nsRenderingContext*, unsigned int) const layout/base/nsDisplayList.cpp:1076 #14 0x7fb563fe32f8 in nsLayoutUtils::PaintFrame(nsRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, unsigned int) layout/base/nsLayoutUtils.cpp:2339 #15 0x7fb563e5cc8d in PresShell::Paint(nsView*, nsRegion const&, unsigned int) layout/base/nsPresShell.cpp:5857 #16 0x7fb562f71aec in nsViewManager::ProcessPendingUpdatesForView(nsView*, bool) view/src/nsViewManager.cpp:420 #17 0x7fb562f745f1 in nsViewManager::ProcessPendingUpdates(nsViewManager::UpdatingMode) view/src/nsViewManager.cpp:1053 #18 0x7fb563e803ba in nsRefreshDriver::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:1207 #19 0x7fb563e84270 in mozilla::RefreshDriverTimer::Tick() layout/base/nsRefreshDriver.cpp:168 #20 0x7fb55fb38f3d in nsTimerImpl::Fire() xpcom/threads/nsTimerImpl.cpp:551 #21 0x7fb55fb396a6 in nsTimerEvent::Run() xpcom/threads/nsTimerImpl.cpp:635 #22 0x7fb55fb31112 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:637 #23 0x7fb55fa07b21 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/glue/nsThreadUtils.cpp:263 #24 0x7fb56035cca1 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:95 #25 0x7fb5602cee63 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:226 #26 0x7fb5624afd6c in nsBaseAppShell::Run() widget/xpwidgets/nsBaseAppShell.cpp:157 #27 0x7fb565177eb6 in nsAppStartup::Run() toolkit/components/startup/nsAppStartup.cpp:276 #28 0x7fb564f9ae28 in XREMain::XRE_mainRun() toolkit/xre/nsAppRunner.cpp:4023 #29 0x7fb564f9bdbd in XREMain::XRE_main(int, char**, nsXREAppData const*) toolkit/xre/nsAppRunner.cpp:4091 #30 0x7fb564f9ccfb in XRE_main toolkit/xre/nsAppRunner.cpp:4331 #31 0x44aa70 in main browser/app/nsBrowserApp.cpp:280 #32 0x7fb56fe8476c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226 #33 0x44a05c in _start 0x611000843b0c is located 8 bytes to the right of 196-byte region [0x611000843a40,0x611000843b04) allocated by thread T0 here: #0 0x433d85 in malloc _asan_rtl_ #1 0x7fb56108bb0b in gfxFontGroup::MakeTextRun(unsigned char const*, unsigned int, gfxTextRunFactory::Parameters const*, unsigned int) gfx/thebes/gfxFont.cpp:5593 #2 0x24637c4e6c452e69 Shadow bytes around the buggy address: 0x0c2280100710: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa 0x0c2280100720: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2280100730: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa 0x0c2280100740: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c2280100750: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0c2280100760: 04[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c2280100770: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x0c2280100780: fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa 0x0c2280100790: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 0x0c22801007a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c22801007b0: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 ASan internal: fe ==26182==ABORTING
Attached file stack+framedump —
We're doing "mRanges[mRanges.Length() - 1]" with mRanges.Length()==0.
I guess the culprit is the code in nsTextFrame::PaintText here: http://hg.mozilla.org/mozilla-central/annotate/8f4ecbf938cd/layout/generic/nsTextFrame.cpp#l5908 Am I doing something wrong when setting up the gfxSkipCharsIterator there?
Severity: normal → critical
Flags: needinfo?(smontagu)
Keywords: crash, testcase
Whiteboard: [asan]
I think roc and/or jfkthame know a lot more than me about gfxSkipCharsIterator
Flags: needinfo?(smontagu)
Flags: needinfo?(roc)
Flags: needinfo?(jfkthame)
Calling this sec-moderate on the assumption that damage is minimized by being during a paint (read only) operation and being limited to a single -1 offset. On the other hand if we're getting the paint wrong do we have the same bug when we're trying to clean things up later? That could be worse.
Summary: Heap-buffer-overflow in SelectionIterator::GetNextSegment → Out of bounds read(4) in SelectionIterator::GetNextSegment
Attachment 8363578 [details] shows some suspicious-sounding assertions before the crash: [16534] ###!!! ASSERTION: frame tree not empty, but caller reported complete status: 'aSubtreeRoot->GetPrevInFlow()', file layout/base/nsLayoutUtils.cpp, line 5098 [16534] ###!!! ASSERTION: Invalid offset: 'uint32_t(aOffset) <= mSkipChars->mCharCount', file gfx/thebes/gfxSkipChars.cpp, line 13 [16534] ###!!! ASSERTION: Invalid offset: 'uint32_t(aOffset) <= mSkipChars->mCharCount', file gfx/thebes/gfxSkipChars.cpp, line 13 Assertion failure: i < Length() (invalid array index), at nsTArray.h:887 In particular, passing out-of-range offsets to a gfxSkipCharsIterator is *not* supported, and is liable to lead to array range errors. I'm guessing we're using a stale gfxSkipChars that is no longer valid, following the modification that's done in the testcase's DOMContentLoaded listener. But I can't seem to reproduce the problem here: the testcase loads without any of those assertions in my debug build. Mats, can you maybe get a stack for the earlier assertions, to see if that helps us work back towards the source of the problem?
Flags: needinfo?(jfkthame) → needinfo?(matspal)
Here you go.
Flags: needinfo?(matspal)
Bug 970710 also triggers the "invalid offset" assertion. Is it related?
(In reply to Jesse Ruderman from comment #7) > Bug 970710 also triggers the "invalid offset" assertion. Is it related? Possibly. I was not able to reproduce this locally; Mats or Jesse, could you re-test using a build that includes bug 970710's patch, which has now landed on inbound? Thanks.
I can't reproduce this bug (tried asan; tried debug), but given comment 5 I'd rather have verification from Mats or Abhishek.
WFM, trunk ASAN debug build on Linux64. Also works (no crash) in non-ASAN debug builds on all branches. Reverting the fix for bug 970710 in the ASAN build and in the release branch build did NOT bring the crash back, so I'd guess something else fixed it. Abhishek, please reopen this bug if you can still reproduce it.
Status: NEW → RESOLVED
Closed: 12 years ago
Flags: in-testsuite?
Resolution: --- → WORKSFORME
Oh, and the assertions are gone too.
Group: core-security
Flags: in-testsuite? → in-testsuite+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: