mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
[CodeView] Make sure StreamRef::readBytes doesn't read too much
llvm-svn: 271418
This commit is contained in:
parent
73419abbaa
commit
818581cd0c
@ -10,6 +10,7 @@
|
||||
#ifndef LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|
||||
#define LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|
||||
|
||||
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
|
||||
#include "llvm/DebugInfo/CodeView/StreamInterface.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -28,6 +29,8 @@ public:
|
||||
|
||||
Error readBytes(uint32_t Offset, uint32_t Size,
|
||||
ArrayRef<uint8_t> &Buffer) const override {
|
||||
if (Size > Length)
|
||||
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
|
||||
return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
|
||||
}
|
||||
|
||||
@ -74,4 +77,4 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|
||||
#endif // LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|
||||
|
@ -71,14 +71,14 @@ private:
|
||||
|
||||
// Tests that a read which is entirely contained within a single block works
|
||||
// and does not allocate.
|
||||
TEST(MappedBlockStreamTest, ZeroCopyReadNoBreak) {
|
||||
TEST(MappedBlockStreamTest, ReadBeyondEndOfStreamRef) {
|
||||
DiscontiguousFile F;
|
||||
MappedBlockStream S(0, F);
|
||||
StreamReader R(S);
|
||||
StringRef Str;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 1));
|
||||
EXPECT_EQ(Str, StringRef("A"));
|
||||
EXPECT_EQ(0U, S.getNumBytesCopied());
|
||||
StreamRef SR;
|
||||
EXPECT_NO_ERROR(R.readStreamRef(SR, 0U));
|
||||
ArrayRef<uint8_t> Buffer;
|
||||
EXPECT_ERROR(SR.readBytes(0U, 1U, Buffer));
|
||||
}
|
||||
|
||||
// Tests that a read which outputs into a full destination buffer works and
|
||||
@ -162,4 +162,16 @@ TEST(MappedBlockStreamTest, InvalidReadSizeNonContiguousBreak) {
|
||||
EXPECT_EQ(0U, S.getNumBytesCopied());
|
||||
}
|
||||
|
||||
// Tests that a read which is entirely contained within a single block but
|
||||
// beyond the end of a StreamRef fails.
|
||||
TEST(MappedBlockStreamTest, ZeroCopyReadNoBreak) {
|
||||
DiscontiguousFile F;
|
||||
MappedBlockStream S(0, F);
|
||||
StreamReader R(S);
|
||||
StringRef Str;
|
||||
EXPECT_NO_ERROR(R.readFixedString(Str, 1));
|
||||
EXPECT_EQ(Str, StringRef("A"));
|
||||
EXPECT_EQ(0U, S.getNumBytesCopied());
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
Loading…
Reference in New Issue
Block a user