Skip to content

Commit

Permalink
oop: Initialize and validate font creation params.
Browse files Browse the repository at this point in the history
This patch ensures that we initialize all font creation params before
reading them and abort creating a typeface if the reader is invalid.

R=enne@chromium.org, ericrk@chromium.org

Bug: 785675
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I7baabeb460c9cb06026c8a82989c7c6f7e970f8f
Reviewed-on: https://chromium-review.googlesource.com/808748
Reviewed-by: Khushal <khushalsagar@chromium.org>
Commit-Queue: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521806}
  • Loading branch information
vmpstr authored and Commit Bot committed Dec 5, 2017
1 parent c550dc1 commit 57a9b3e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cc/paint/paint_op_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) {
// implemented. So this should be a failure (ie |valid_| = false).
break;
case PaintTypeface::Type::kFontConfigInterfaceIdAndTtcIndex: {
int font_config_interface_id;
int ttc_index;
int font_config_interface_id = 0;
int ttc_index = 0;
ReadSimple(&font_config_interface_id);
ReadSimple(&ttc_index);
if (!valid_)
return;
typeface = PaintTypeface::FromFontConfigInterfaceIdAndTtcIndex(
font_config_interface_id, ttc_index);
break;
Expand All @@ -312,8 +314,10 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) {
ReadData(size, buffer.get());
std::string filename(buffer.get(), size);

int ttc_index;
int ttc_index = 0;
ReadSimple(&ttc_index);
if (!valid_)
return;
typeface = PaintTypeface::FromFilenameAndTtcIndex(filename, ttc_index);
break;
}
Expand All @@ -329,12 +333,15 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) {
ReadData(size, buffer.get());
std::string family_name(buffer.get(), size);

int weight;
int width;
SkFontStyle::Slant slant;
int weight = 0;
int width = 0;
SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
ReadSimple(&weight);
ReadSimple(&width);
ReadSimple(&slant);
if (!valid_)
return;

typeface = PaintTypeface::FromFamilyNameAndFontStyle(
family_name, SkFontStyle(weight, width, slant));
break;
Expand Down Expand Up @@ -502,7 +509,7 @@ void PaintOpReader::AlignMemory(size_t alignment) {
// however, since it can be slow.
size_t padding = ((memory + alignment - 1) & ~(alignment - 1)) - memory;
if (padding > remaining_bytes_)
valid_ = false;
SetInvalid();

memory_ += padding;
remaining_bytes_ -= padding;
Expand Down

0 comments on commit 57a9b3e

Please sign in to comment.