[llvm] r271418 - [CodeView] Make sure StreamRef::readBytes doesn't read too much
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 1 11:13:06 PDT 2016
Author: majnemer
Date: Wed Jun 1 13:13:06 2016
New Revision: 271418
URL: http://llvm.org/viewvc/llvm-project?rev=271418&view=rev
Log:
[CodeView] Make sure StreamRef::readBytes doesn't read too much
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h
llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h?rev=271418&r1=271417&r2=271418&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h Wed Jun 1 13:13:06 2016
@@ -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
\ No newline at end of file
+#endif // LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
Modified: llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp?rev=271418&r1=271417&r2=271418&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp Wed Jun 1 13:13:06 2016
@@ -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, InvalidReadS
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
More information about the llvm-commits
mailing list