Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 81d9dfc

Browse files
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271496 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f117b3a commit 81d9dfc

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

include/llvm/DebugInfo/CodeView/StreamRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class StreamRef : public StreamInterface {
2929

3030
Error readBytes(uint32_t Offset, uint32_t Size,
3131
ArrayRef<uint8_t> &Buffer) const override {
32-
if (Size > Length)
32+
if (Size + Offset > Length)
3333
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
3434
return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
3535
}

unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ TEST(MappedBlockStreamTest, ReadBeyondEndOfStreamRef) {
7979
EXPECT_NO_ERROR(R.readStreamRef(SR, 0U));
8080
ArrayRef<uint8_t> Buffer;
8181
EXPECT_ERROR(SR.readBytes(0U, 1U, Buffer));
82+
EXPECT_NO_ERROR(R.readStreamRef(SR, 1U));
83+
EXPECT_ERROR(SR.readBytes(1U, 1U, Buffer));
8284
}
8385

8486
// Tests that a read which outputs into a full destination buffer works and

0 commit comments

Comments
 (0)