SkValidatingReadBuffer.h revision 18f13f3673c20fec220a1594b3174f9dcab35c5d
1/* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkValidatingReadBuffer_DEFINED 9#define SkValidatingReadBuffer_DEFINED 10 11#include "SkRefCnt.h" 12#include "SkBitmapHeap.h" 13#include "SkReadBuffer.h" 14#include "SkWriteBuffer.h" 15#include "SkPath.h" 16#include "SkPicture.h" 17#include "SkReader32.h" 18 19class SkBitmap; 20 21class SkValidatingReadBuffer : public SkReadBuffer { 22public: 23 SkValidatingReadBuffer(const void* data, size_t size); 24 ~SkValidatingReadBuffer() override; 25 26 SkReadBuffer* clone(const void* data, size_t size) const override { 27 return new SkValidatingReadBuffer(data, size); 28 } 29 30 const void* skip(size_t size) override; 31 32 // primitives 33 bool readBool() override; 34 SkColor readColor() override; 35 int32_t readInt() override; 36 SkScalar readScalar() override; 37 uint32_t readUInt() override; 38 int32_t read32() override; 39 40 // peek 41 uint8_t peekByte() override; 42 43 // strings -- the caller is responsible for freeing the string contents 44 void readString(SkString* string) override; 45 46 // common data structures 47 SkFlattenable* readFlattenable(SkFlattenable::Type type) override; 48 void readPoint(SkPoint* point) override; 49 void readMatrix(SkMatrix* matrix) override; 50 void readIRect(SkIRect* rect) override; 51 void readRect(SkRect* rect) override; 52 void readRRect(SkRRect* rrect) override; 53 void readRegion(SkRegion* region) override; 54 void readPath(SkPath* path) override; 55 56 // binary data and arrays 57 bool readByteArray(void* value, size_t size) override; 58 bool readColorArray(SkColor* colors, size_t size) override; 59 bool readIntArray(int32_t* values, size_t size) override; 60 bool readPointArray(SkPoint* points, size_t size) override; 61 bool readScalarArray(SkScalar* values, size_t size) override; 62 63 // helpers to get info about arrays and binary data 64 uint32_t getArrayCount() override; 65 66 // TODO: Implement this (securely) when needed 67 SkTypeface* readTypeface() override; 68 69 bool validate(bool isValid) override; 70 bool isValid() const override; 71 72 bool validateAvailable(size_t size) override; 73 74private: 75 bool readArray(void* value, size_t size, size_t elementSize); 76 77 void setMemory(const void* data, size_t size); 78 79 static bool IsPtrAlign4(const void* ptr) { 80 return SkIsAlign4((uintptr_t)ptr); 81 } 82 83 bool fError; 84 85 typedef SkReadBuffer INHERITED; 86}; 87 88#endif // SkValidatingReadBuffer_DEFINED 89