Bug 1153613 - [e10s], ensure the buffer for the drag image is large enough for SourceSurfaceRawData::GuaranteePersistance() to succeed, r=mattwoodrow

--HG--
extra : rebase_source : a5c44e35f34f4ec1f34aac90a275016915b75798
This commit is contained in:
Olli Pettay 2015-04-14 13:50:59 +03:00
parent 62590c615c
commit 98be5bf81a
2 changed files with 13 additions and 4 deletions

View File

@ -2983,7 +2983,8 @@ TabParent::RecvInvokeDragSession(nsTArray<IPCDataTransfer>&& aTransfers,
}
}
if (aVisualDnDData.IsEmpty()) {
if (aVisualDnDData.IsEmpty() ||
(aVisualDnDData.Length() < aHeight * aStride)) {
mDnDVisualization = nullptr;
} else {
mDnDVisualization =

View File

@ -9,6 +9,7 @@
#include "nsISupportsPrimitives.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/unused.h"
#include "nsContentUtils.h"
@ -62,12 +63,19 @@ nsDragServiceProxy::InvokeDragSession(nsIDOMNode* aDOMNode,
mozilla::gfx::IntSize size = dataSurface->GetSize();
mozilla::CheckedInt32 requiredBytes =
mozilla::CheckedInt32(map.mStride) * mozilla::CheckedInt32(size.height);
size_t bufLen = requiredBytes.isValid() ? requiredBytes.value() : 0;
size_t maxBufLen = requiredBytes.isValid() ? requiredBytes.value() : 0;
mozilla::gfx::SurfaceFormat format = dataSurface->GetFormat();
// Surface data handling is totally nuts. This is the magic one needs to
// know to access the data.
bufLen = bufLen - map.mStride + (size.width * BytesPerPixel(format));
nsDependentCString dragImage(reinterpret_cast<char*>(map.mData), bufLen);
size_t bufLen =
maxBufLen - map.mStride + (size.width * BytesPerPixel(format));
// nsDependentCString wants null-terminated string.
mozilla::UniquePtr<char[]> dragImageData(new char[maxBufLen + 1]);
memcpy(dragImageData.get(), reinterpret_cast<char*>(map.mData), bufLen);
memset(dragImageData.get() + bufLen, 0, maxBufLen - bufLen + 1);
nsDependentCString dragImage(dragImageData.get(), maxBufLen);
mozilla::unused <<
child->SendInvokeDragSession(dataTransfers, aActionType, dragImage,
size.width, size.height, map.mStride,