Commit 57a9b3e3 authored by Vladimir Levin's avatar Vladimir Levin Committed by Commit Bot

oop: Initialize and validate font creation params.

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/808748Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521806}
parent c550dc16
...@@ -292,10 +292,12 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) { ...@@ -292,10 +292,12 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) {
// implemented. So this should be a failure (ie |valid_| = false). // implemented. So this should be a failure (ie |valid_| = false).
break; break;
case PaintTypeface::Type::kFontConfigInterfaceIdAndTtcIndex: { case PaintTypeface::Type::kFontConfigInterfaceIdAndTtcIndex: {
int font_config_interface_id; int font_config_interface_id = 0;
int ttc_index; int ttc_index = 0;
ReadSimple(&font_config_interface_id); ReadSimple(&font_config_interface_id);
ReadSimple(&ttc_index); ReadSimple(&ttc_index);
if (!valid_)
return;
typeface = PaintTypeface::FromFontConfigInterfaceIdAndTtcIndex( typeface = PaintTypeface::FromFontConfigInterfaceIdAndTtcIndex(
font_config_interface_id, ttc_index); font_config_interface_id, ttc_index);
break; break;
...@@ -312,8 +314,10 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) { ...@@ -312,8 +314,10 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) {
ReadData(size, buffer.get()); ReadData(size, buffer.get());
std::string filename(buffer.get(), size); std::string filename(buffer.get(), size);
int ttc_index; int ttc_index = 0;
ReadSimple(&ttc_index); ReadSimple(&ttc_index);
if (!valid_)
return;
typeface = PaintTypeface::FromFilenameAndTtcIndex(filename, ttc_index); typeface = PaintTypeface::FromFilenameAndTtcIndex(filename, ttc_index);
break; break;
} }
...@@ -329,12 +333,15 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) { ...@@ -329,12 +333,15 @@ void PaintOpReader::Read(std::vector<PaintTypeface>* typefaces) {
ReadData(size, buffer.get()); ReadData(size, buffer.get());
std::string family_name(buffer.get(), size); std::string family_name(buffer.get(), size);
int weight; int weight = 0;
int width; int width = 0;
SkFontStyle::Slant slant; SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
ReadSimple(&weight); ReadSimple(&weight);
ReadSimple(&width); ReadSimple(&width);
ReadSimple(&slant); ReadSimple(&slant);
if (!valid_)
return;
typeface = PaintTypeface::FromFamilyNameAndFontStyle( typeface = PaintTypeface::FromFamilyNameAndFontStyle(
family_name, SkFontStyle(weight, width, slant)); family_name, SkFontStyle(weight, width, slant));
break; break;
...@@ -502,7 +509,7 @@ void PaintOpReader::AlignMemory(size_t alignment) { ...@@ -502,7 +509,7 @@ void PaintOpReader::AlignMemory(size_t alignment) {
// however, since it can be slow. // however, since it can be slow.
size_t padding = ((memory + alignment - 1) & ~(alignment - 1)) - memory; size_t padding = ((memory + alignment - 1) & ~(alignment - 1)) - memory;
if (padding > remaining_bytes_) if (padding > remaining_bytes_)
valid_ = false; SetInvalid();
memory_ += padding; memory_ += padding;
remaining_bytes_ -= padding; remaining_bytes_ -= padding;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment