1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
commit 85ac1989f1c2
Author: Lee Salzman <lsalzman@mozilla.com>
Date: Mon Feb 19 21:19:53 2018 -0500
Bug 1427118 - Make RecordedFontData use fallible allocations. r=milan, a=RyanVM
MozReview-Commit-ID: 3YzhOyXvrv
--HG--
extra : source : a35fe8a4a82de45e10627b6fc760dd13d5df64a8
---
gfx/2d/RecordedEventImpl.h | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git gfx/2d/RecordedEventImpl.h gfx/2d/RecordedEventImpl.h
index bc1cec648302..0e8efb032cdf 100644
--- gfx/2d/RecordedEventImpl.h
+++ gfx/2d/RecordedEventImpl.h
@@ -913,7 +913,7 @@ public:
, mType(aUnscaledFont->GetType())
, mData(nullptr)
{
- mGetFontFileDataSucceeded = aUnscaledFont->GetFontFileData(&FontDataProc, this);
+ mGetFontFileDataSucceeded = aUnscaledFont->GetFontFileData(&FontDataProc, this) && mData;
}
~RecordedFontData();
@@ -2518,11 +2518,12 @@ RecordedSourceSurfaceCreation::RecordedSourceSurfaceCreation(S &aStream)
ReadElement(aStream, mRefPtr);
ReadElement(aStream, mSize);
ReadElement(aStream, mFormat);
- mData = (uint8_t*)new (fallible) char[mSize.width * mSize.height * BytesPerPixel(mFormat)];
+ size_t size = mSize.width * mSize.height * BytesPerPixel(mFormat);
+ mData = new (fallible) uint8_t[size];
if (!mData) {
- gfxWarning() << "RecordedSourceSurfaceCreation failed to allocate data";
+ gfxCriticalNote << "RecordedSourceSurfaceCreation failed to allocate data of size " << size;
} else {
- aStream.read((char*)mData, mSize.width * mSize.height * BytesPerPixel(mFormat));
+ aStream.read((char*)mData, size);
}
}
@@ -2767,6 +2768,10 @@ RecordedFontData::~RecordedFontData()
inline bool
RecordedFontData::PlayEvent(Translator *aTranslator) const
{
+ if (!mData) {
+ return false;
+ }
+
RefPtr<NativeFontResource> fontResource =
Factory::CreateNativeFontResource(mData, mFontDetails.size,
aTranslator->GetReferenceDrawTarget()->GetBackendType(),
@@ -2800,8 +2805,12 @@ RecordedFontData::OutputSimpleEventInfo(std::stringstream &aStringStream) const
inline void
RecordedFontData::SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex)
{
- mData = new uint8_t[aSize];
- memcpy(mData, aData, aSize);
+ mData = new (fallible) uint8_t[aSize];
+ if (!mData) {
+ gfxCriticalNote << "RecordedFontData failed to allocate data for recording of size " << aSize;
+ } else {
+ memcpy(mData, aData, aSize);
+ }
mFontDetails.fontDataKey =
SFNTData::GetUniqueKey(aData, aSize, 0, nullptr);
mFontDetails.size = aSize;
@@ -2830,8 +2839,12 @@ RecordedFontData::RecordedFontData(S &aStream)
ReadElement(aStream, mType);
ReadElement(aStream, mFontDetails.fontDataKey);
ReadElement(aStream, mFontDetails.size);
- mData = new uint8_t[mFontDetails.size];
- aStream.read((char*)mData, mFontDetails.size);
+ mData = new (fallible) uint8_t[mFontDetails.size];
+ if (!mData) {
+ gfxCriticalNote << "RecordedFontData failed to allocate data for playback of size " << mFontDetails.size;
+ } else {
+ aStream.read((char*)mData, mFontDetails.size);
+ }
}
inline
|