--- src/core/SkReadBuffer.cpp.orig +++ src/core/SkReadBuffer.cpp @@ -127,12 +127,12 @@ return this->readInt(); } -uint8_t SkReadBuffer::peekByte() { - if (this->available() <= 0) { +uint8_t SkReadBuffer::peekByte(size_t offs) { + if (this->available() <= offs) { fError = true; return 0; } - return *((const uint8_t*)fCurr); + return ((const uint8_t*)fCurr)[offs]; } bool SkReadBuffer::readPad32(void* buffer, size_t bytes) { @@ -488,7 +488,15 @@ } factory = fFactoryArray[index]; } else { - if (this->peekByte() != 0) { + // The writer stores a dictionary index as (index << 8) so that the first byte written + // is zero and can act as a "this is an index, not a string" sentinel. The first byte + // written is the low byte of the 32-bit word on little endian, the high byte on big. +#ifdef SK_CPU_BENDIAN + constexpr size_t kSentinelByte = 3; +#else + constexpr size_t kSentinelByte = 0; +#endif + if (this->peekByte(kSentinelByte) != 0) { // If the first byte is non-zero, the flattenable is specified by a string. size_t ignored_length; if (const char* name = this->readString(&ignored_length)) {