diff options
Diffstat (limited to 'src/vm/nativeformatreader.h')
-rw-r--r-- | src/vm/nativeformatreader.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/vm/nativeformatreader.h b/src/vm/nativeformatreader.h index 4182b032c4..fdeadfedc4 100644 --- a/src/vm/nativeformatreader.h +++ b/src/vm/nativeformatreader.h @@ -54,35 +54,50 @@ namespace NativeFormat uint EnsureOffsetInRange(uint offset, uint lookAhead) { if ((int)offset < 0 || offset + lookAhead >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } return offset; } byte ReadUInt8(uint offset) { if (offset >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } return *(_base + offset); // Assumes little endian and unaligned access } UInt16 ReadUInt16(uint offset) { if ((int)offset < 0 || offset + 1 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } return *dac_cast<PTR_USHORT>(_base + offset); // Assumes little endian and unaligned access } UInt32 ReadUInt32(uint offset) { if ((int)offset < 0 || offset + 3 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } return *dac_cast<PTR_UINT32>(_base + offset); // Assumes little endian and unaligned access } uint DecodeUnsigned(uint offset, uint * pValue) { if (offset >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } uint val = *(_base + offset); if ((val & 1) == 0) @@ -94,7 +109,10 @@ namespace NativeFormat if ((val & 2) == 0) { if (offset + 1 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } *pValue = (val >> 2) | (((uint)*(_base + offset + 1)) << 6); offset += 2; @@ -103,7 +121,10 @@ namespace NativeFormat if ((val & 4) == 0) { if (offset + 2 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } *pValue = (val >> 3) | (((uint)*(_base + offset + 1)) << 5) | (((uint)*(_base + offset + 2)) << 13); @@ -113,7 +134,10 @@ namespace NativeFormat if ((val & 8) == 0) { if (offset + 3 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } *pValue = (val >> 4) | (((uint)*(_base + offset + 1)) << 4) | (((uint)*(_base + offset + 2)) << 12) | @@ -128,6 +152,7 @@ namespace NativeFormat } else { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); } @@ -137,7 +162,10 @@ namespace NativeFormat int DecodeSigned(uint offset, int * pValue) { if (offset >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } int val = *(_base + offset); if ((val & 1) == 0) @@ -148,7 +176,10 @@ namespace NativeFormat else if ((val & 2) == 0) { if (offset + 1 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } *pValue = (val >> 2) | (((int)*(_base + offset + 1)) << 6); offset += 2; @@ -156,7 +187,10 @@ namespace NativeFormat else if ((val & 4) == 0) { if (offset + 2 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } *pValue = (val >> 3) | (((int)*(_base + offset + 1)) << 5) | (((int)*(_base + offset + 2)) << 13); @@ -165,7 +199,10 @@ namespace NativeFormat else if ((val & 8) == 0) { if (offset + 3 >= _size) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); + } *pValue = (val >> 4) | (((int)*(_base + offset + 1)) << 4) | (((int)*(_base + offset + 2)) << 12) | @@ -179,6 +216,7 @@ namespace NativeFormat } else { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); } @@ -220,6 +258,7 @@ namespace NativeFormat } else { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); ThrowBadImageFormatException(); return offset; } @@ -450,12 +489,18 @@ namespace NativeFormat int numberOfBucketsShift = (int)(header >> 2); if (numberOfBucketsShift > 31) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); _pReader->ThrowBadImageFormatException(); + } _bucketMask = (uint)((1 << numberOfBucketsShift) - 1); byte entryIndexSize = (byte)(header & 3); if (entryIndexSize > 2) + { + fprintf(stderr, "@@[SR] %s:%d\n", __FILE__, __LINE__); _pReader->ThrowBadImageFormatException(); + } _entryIndexSize = entryIndexSize; } |