Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Unified Diff: src/pdf/SkPDFFont.cpp

Issue 1842163002: SkPDF: SkTypeface::openStream could return nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFFont.cpp
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index c42092c09d0d47ef2c919e9bcf5f0466bd5d574d..8718596b8eb7b659ab2bdc59ebe0ea26b16522ac 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -590,7 +590,10 @@ static size_t get_subset_font_stream(const char* fontName,
SkPDFStream** fontStream) {
int ttcIndex;
std::unique_ptr<SkStream> fontData(typeface->openStream(&ttcIndex));
- SkASSERT(fontData.get());
+ SkASSERT(fontData);
+ if (!fontData) {
+ return 0;
+ }
size_t fontSize = fontData->getLength();
@@ -1047,6 +1050,9 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
typeface(),
*subset,
&rawStream);
+ if (0 == fontSize) {
+ return false;
+ }
if (rawStream) {
fontStream.reset(rawStream);
fontStream->insertInt("Length1", fontSize);
@@ -1059,6 +1065,9 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
std::unique_ptr<SkStreamAsset> fontData(
this->typeface()->openStream(nullptr));
SkASSERT(fontData);
+ if (!fontData || 0 == fontData->getLength()) {
+ return false;
+ }
fontSize = fontData->getLength();
SkASSERT(fontSize > 0);
fontStream.reset(new SkPDFSharedStream(fontData.release()));
@@ -1068,9 +1077,15 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
}
case SkAdvancedTypefaceMetrics::kCFF_Font:
case SkAdvancedTypefaceMetrics::kType1CID_Font: {
+ std::unique_ptr<SkStreamAsset> fontData(
+ this->typeface()->openStream(nullptr));
+ SkASSERT(fontData);
+ SkASSERT(fontData->getLength() > 0);
+ if (!fontData || 0 == fontData->getLength()) {
+ return false;
+ }
sk_sp<SkPDFSharedStream> fontStream(
- new SkPDFSharedStream(this->typeface()->openStream(nullptr)));
-
+ new SkPDFSharedStream(fontData.release()));
if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) {
fontStream->dict()->insertName("Subtype", "Type1C");
} else {
@@ -1198,7 +1213,12 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
size_t header SK_INIT_TO_AVOID_WARNING;
size_t data SK_INIT_TO_AVOID_WARNING;
size_t trailer SK_INIT_TO_AVOID_WARNING;
- std::unique_ptr<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
+ std::unique_ptr<SkStreamAsset> rawFontData(typeface()->openStream(&ttcIndex));
+ SkASSERT(rawFontData);
+ SkASSERT(rawFontData->getLength() > 0);
+ if (!rawFontData || 0 == rawFontData->getLength()) {
+ return false;
+ }
sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header,
&data, &trailer));
if (fontData.get() == nullptr) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698