From 364d704041e4ecbb772f70389944150be5e7b4a8 Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Sat, 7 May 2022 06:50:47 +0000 Subject: [PATCH] Bug 1765871. Deal with oriented image frames in imgFrame::Finish. r=aosmond Differential Revision: https://phabricator.services.mozilla.com/D144390 --- image/Decoder.cpp | 5 +++- image/imgFrame.cpp | 34 +++++++++++++++++++------- image/imgFrame.h | 3 ++- image/test/crashtests/1765871-1.jpg | Bin 0 -> 6872 bytes image/test/crashtests/crashtests.list | 1 + 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 image/test/crashtests/1765871-1.jpg diff --git a/image/Decoder.cpp b/image/Decoder.cpp index 595f5dfcf542..76301d7596b8 100644 --- a/image/Decoder.cpp +++ b/image/Decoder.cpp @@ -477,7 +477,10 @@ void Decoder::PostFrameStop(Opacity aFrameOpacity) { mInFrame = false; mFinishedNewFrame = true; - mCurrentFrame->Finish(aFrameOpacity, mFinalizeFrames); + mCurrentFrame->Finish( + aFrameOpacity, mFinalizeFrames, + /* aOrientationSwapsWidthAndHeight = */ mImageMetadata.HasOrientation() && + mImageMetadata.GetOrientation().SwapsWidthAndHeight()); mProgress |= FLAG_FRAME_COMPLETE; diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index e58c3dd5b2d4..4ff6dcec1977 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -522,23 +522,39 @@ nsresult imgFrame::ImageUpdatedInternal(const nsIntRect& aUpdateRect) { } void imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */, - bool aFinalize /* = true */) { + bool aFinalize /* = true */, + bool aOrientationSwapsWidthAndHeight /* = false */) { MonitorAutoLock lock(mMonitor); IntRect frameRect(GetRect()); if (!mDecoded.IsEqualEdges(frameRect)) { // The decoder should have produced rows starting from either the bottom or // the top of the image. We need to calculate the region for which we have - // not yet invalidated. + // not yet invalidated. And if the orientation swaps width and height then + // its from the left or right. IntRect delta(0, 0, frameRect.width, 0); - if (mDecoded.y == 0) { - delta.y = mDecoded.height; - delta.height = frameRect.height - mDecoded.height; - } else if (mDecoded.y + mDecoded.height == frameRect.height) { - delta.height = frameRect.height - mDecoded.y; + if (!aOrientationSwapsWidthAndHeight) { + delta.width = frameRect.width; + if (mDecoded.y == 0) { + delta.y = mDecoded.height; + delta.height = frameRect.height - mDecoded.height; + } else if (mDecoded.y + mDecoded.height == frameRect.height) { + delta.height = frameRect.height - mDecoded.y; + } else { + MOZ_ASSERT_UNREACHABLE("Decoder only updated middle of image!"); + delta = frameRect; + } } else { - MOZ_ASSERT_UNREACHABLE("Decoder only updated middle of image!"); - delta = frameRect; + delta.height = frameRect.height; + if (mDecoded.x == 0) { + delta.x = mDecoded.width; + delta.width = frameRect.width - mDecoded.width; + } else if (mDecoded.x + mDecoded.width == frameRect.width) { + delta.width = frameRect.width - mDecoded.x; + } else { + MOZ_ASSERT_UNREACHABLE("Decoder only updated middle of image!"); + delta = frameRect; + } } ImageUpdatedInternal(delta); diff --git a/image/imgFrame.h b/image/imgFrame.h index 242ccebb1af9..e76f27d6a774 100644 --- a/image/imgFrame.h +++ b/image/imgFrame.h @@ -109,7 +109,8 @@ class imgFrame { * may be marked as read only if possible). */ void Finish(Opacity aFrameOpacity = Opacity::SOME_TRANSPARENCY, - bool aFinalize = true); + bool aFinalize = true, + bool aOrientationSwapsWidthAndHeight = false); /** * Mark this imgFrame as aborted. This informs the imgFrame that if it isn't diff --git a/image/test/crashtests/1765871-1.jpg b/image/test/crashtests/1765871-1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..11460a62c30b62920d6347ef780649d3b23bce29 GIT binary patch literal 6872 zcmeHLcT`i&wx5#<0i+i}P3TPspj3g-i-;f~h%Lq>Km-DYAYhB4qGG`ccCd?$&jx}e ziUklGHtc|iAXtJ(PjcP_{37?Rd+)pJyMMg3-nzr$@SB;v_sst7J#+Q}eTg;#waEd& z0RTY|5Cne!`ayX{u&*yYJR&S0c#1!q06;lt3WuA5Q3D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RuugBgaXlW;k!qD#{(sEsp8fKsXMu+ z69qbt1TPW=t(Q^IpQZXY!g(V^iQ-xCY{#BK!GUHJw0xvBouIV`qM&v!3T_V2KI|uV zX9~Lt1$`oNXHu^uu1vZl4+RBVP>@rEf?_fXY*SD`Y(qgVU-0|`3LY*)LGum4oeK@! zdm8$`(WG;IrTVL+M+D+>p_qJFYFUSZ7Lrmh@l_OvwMr&QEe#;QcoghA zjDma9=$&zelB5h2cn~31>u61-!ghFBwX~w3@hG`7s9~U*DsCZ5BUVYr!&~OeW)!qS zqWkNJBh5k@M_LUR+}R`OKGz`r3FF~Lfw6fF?<;tr78If&dxzkTv7mz@?AjsdpRC$< zAxv6235I(WwCqO~y`gtcfmzfAvnV33??{S-r7PvZ5L=ase)T>fy#pp_B;tjK{}KyFyvRP8 zWT}5LRoWo<*_<)=u5O7JWMvm}@KTFsf0q^Hh_YUi#!6NyMy1k?IQB$hC zd(a)4H!3YaL5gr-;gu4ml9(juL4mZuc;Lz{dcVRa}oZ&S~(l0w>=N_ls+h$hZ`O_yAUd${}U+D59#60(JY vf!TTO-&F)3b87_OAb+QlvR=e^_j=2d#k~GeVP%uN``_G=9U)ontbFx9dD}=U literal 0 HcmV?d00001 diff --git a/image/test/crashtests/crashtests.list b/image/test/crashtests/crashtests.list index ecb517dca2d4..d9f27ff3a0c2 100644 --- a/image/test/crashtests/crashtests.list +++ b/image/test/crashtests/crashtests.list @@ -68,3 +68,4 @@ HTTP load 1634839-1.html HTTP load 1634839-2.html pref(image.animated.decode-on-demand.batch-size,1) pref(image.animated.decode-on-demand.threshold-kb,0) HTTP load 1676172-1.html pref(browser.soft_reload.only_force_validate_top_level_document,false) HTTP load 1763581-1.html +load 1765871-1.jpg