aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Schimpf <kschimpf@google.com>2013-06-13 13:12:03 -0700
committerKarl Schimpf <kschimpf@google.com>2013-06-13 13:12:03 -0700
commit5d2171152d8441be311af367276e7e016877c05c (patch)
treee43213eb4b12676133ece44038cf5c66265b67a9
parentdfb5a31ae3d5c3ec9db280941422dc4160d0822d (diff)
Fix reading of headers when using a streamable memory object.
Fixes bug where we computed the length of fields buffer on the size of a pointer, rather then the actual length of the field. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3485 R=dschuff@chromium.org Review URL: https://codereview.chromium.org/17003002
-rw-r--r--include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h4
-rw-r--r--lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp10
2 files changed, 8 insertions, 6 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h b/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h
index 6e35f62067..8febf95564 100644
--- a/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h
+++ b/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h
@@ -22,7 +22,7 @@
#include <vector>
namespace llvm {
-class StreamingMemoryObject;
+class StreamableMemoryObject;
// Class representing a variable-size metadata field in the bitcode header.
// Also contains the list of known (typed) Tag IDs.
@@ -167,7 +167,7 @@ public:
// \brief Read the PNaCl bitcode header, recording the fields found
// in the header. Returns false if able to read (all of) the bitcode header.
- bool Read(StreamingMemoryObject *Bytes);
+ bool Read(StreamableMemoryObject *Bytes);
// \brief Returns the number of bytes read to consume the header.
size_t getHeaderSize() { return HeaderSize; }
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp
index 5193417619..aa73b9cffa 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeHeader.cpp
@@ -187,7 +187,7 @@ bool NaClBitcodeHeader::Read(const unsigned char *&BufPtr,
return false;
}
-bool NaClBitcodeHeader::Read(StreamingMemoryObject *Bytes) {
+bool NaClBitcodeHeader::Read(StreamableMemoryObject *Bytes) {
unsigned NumFields;
unsigned NumBytes;
{
@@ -197,12 +197,14 @@ bool NaClBitcodeHeader::Read(StreamingMemoryObject *Bytes) {
return true;
}
uint8_t *Header = new uint8_t[NumBytes];
- bool results =
+ bool failed =
Bytes->readBytes(2 * WordSize, NumBytes, Header, NULL) ||
- ReadFields(Header, Header + sizeof(Header), NumFields, NumBytes);
+ ReadFields(Header, Header + NumBytes, NumFields, NumBytes);
delete[] Header;
+ if (failed)
+ return true;
InstallFields();
- return results;
+ return false;
}
NaClBitcodeHeaderField *