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

Side by Side Diff: src/core/SkPictureShader.cpp

Issue 1151663002: Don't serialize SkPictures in SkPictureShaders when in untrusted mode. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: tweak Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkReadBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPictureShader.h" 8 #include "SkPictureShader.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 116
117 SkShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMo de tmy, 117 SkShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMo de tmy,
118 const SkMatrix* localMatrix, const SkRe ct* tile) { 118 const SkMatrix* localMatrix, const SkRe ct* tile) {
119 if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) { 119 if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) {
120 return SkShader::CreateEmptyShader(); 120 return SkShader::CreateEmptyShader();
121 } 121 }
122 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile)); 122 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile));
123 } 123 }
124 124
125 // TODO: rename SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS to SK_DISALLOW_CROS SPROCESS_PICTURES
126
125 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { 127 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) {
126 SkMatrix lm; 128 SkMatrix lm;
127 buffer.readMatrix(&lm); 129 buffer.readMatrix(&lm);
128 TileMode mx = (TileMode)buffer.read32(); 130 TileMode mx = (TileMode)buffer.read32();
129 TileMode my = (TileMode)buffer.read32(); 131 TileMode my = (TileMode)buffer.read32();
130 SkRect tile; 132 SkRect tile;
131 buffer.readRect(&tile); 133 buffer.readRect(&tile);
132 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromBuffer(buffer)); 134
135 SkAutoTUnref<SkPicture> picture;
136 #ifdef SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS
137 if (buffer.isCrossProcess()) {
138 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n)) {
139 // Older code blindly serialized pictures. We don't trust them.
140 buffer.validate(false);
141 return NULL;
142 }
143 // Newer code won't serialize pictures in disallow-cross-process-picture mode.
144 // Assert that they didn't serialize anything except a false here.
145 buffer.validate(!buffer.readBool());
146 } else
147 #endif
148 {
149 // Old code always serialized the picture. New code writes a 'true' fir st if it did.
150 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n) ||
151 buffer.readBool()) {
152 picture.reset(SkPicture::CreateFromBuffer(buffer));
153 }
154 }
133 return SkPictureShader::Create(picture, mx, my, &lm, &tile); 155 return SkPictureShader::Create(picture, mx, my, &lm, &tile);
134 } 156 }
135 157
136 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { 158 void SkPictureShader::flatten(SkWriteBuffer& buffer) const {
137 buffer.writeMatrix(this->getLocalMatrix()); 159 buffer.writeMatrix(this->getLocalMatrix());
138 buffer.write32(fTmx); 160 buffer.write32(fTmx);
139 buffer.write32(fTmy); 161 buffer.write32(fTmy);
140 buffer.writeRect(fTile); 162 buffer.writeRect(fTile);
141 fPicture->flatten(buffer); 163
164 #ifdef SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS
165 // The deserialization code won't trust that our serialized picture is safe to deserialize.
166 // So write a 'false' telling it that we're not serializing a picture.
167 if (buffer.isCrossProcess()) {
168 buffer.writeBool(false);
169 } else
170 #endif
171 {
172 buffer.writeBool(true);
173 fPicture->flatten(buffer);
174 }
142 } 175 }
143 176
144 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri x* localM, 177 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri x* localM,
145 const int maxTextureSize) const { 178 const int maxTextureSize) const {
146 SkASSERT(fPicture && !fPicture->cullRect().isEmpty()); 179 SkASSERT(fPicture && !fPicture->cullRect().isEmpty());
147 180
148 SkMatrix m; 181 SkMatrix m;
149 m.setConcat(matrix, this->getLocalMatrix()); 182 m.setConcat(matrix, this->getLocalMatrix());
150 if (localM) { 183 if (localM) {
151 m.preConcat(*localM); 184 m.preConcat(*localM);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC olor, fp); 354 return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC olor, fp);
322 } 355 }
323 #else 356 #else
324 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&, 357 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&,
325 const SkMatrix*, GrColor*, 358 const SkMatrix*, GrColor*,
326 GrFragmentProcessor**) const { 359 GrFragmentProcessor**) const {
327 SkDEBUGFAIL("Should not call in GPU-less build"); 360 SkDEBUGFAIL("Should not call in GPU-less build");
328 return false; 361 return false;
329 } 362 }
330 #endif 363 #endif
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkReadBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698