[CodeView] Take the StreamRef::readBytes offset into account when validating
We only considered the length of the operation and the length of the StreamRef without considered what it meant for the offset to be at a non-zero position. llvm-svn: 271496
This commit is contained in:
parent
afefa67310
commit
8c79db1741
|
@ -29,7 +29,7 @@ public:
|
||||||
|
|
||||||
Error readBytes(uint32_t Offset, uint32_t Size,
|
Error readBytes(uint32_t Offset, uint32_t Size,
|
||||||
ArrayRef<uint8_t> &Buffer) const override {
|
ArrayRef<uint8_t> &Buffer) const override {
|
||||||
if (Size > Length)
|
if (Size + Offset > Length)
|
||||||
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
|
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
|
||||||
return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
|
return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,8 @@ TEST(MappedBlockStreamTest, ReadBeyondEndOfStreamRef) {
|
||||||
EXPECT_NO_ERROR(R.readStreamRef(SR, 0U));
|
EXPECT_NO_ERROR(R.readStreamRef(SR, 0U));
|
||||||
ArrayRef<uint8_t> Buffer;
|
ArrayRef<uint8_t> Buffer;
|
||||||
EXPECT_ERROR(SR.readBytes(0U, 1U, Buffer));
|
EXPECT_ERROR(SR.readBytes(0U, 1U, Buffer));
|
||||||
|
EXPECT_NO_ERROR(R.readStreamRef(SR, 1U));
|
||||||
|
EXPECT_ERROR(SR.readBytes(1U, 1U, Buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a read which outputs into a full destination buffer works and
|
// Tests that a read which outputs into a full destination buffer works and
|
||||||
|
|
Loading…
Reference in New Issue