Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions c++/src/Reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ namespace orc {
const proto::Stream& stream = currentStripeFooter.streams(i);
uint64_t length = static_cast<uint64_t>(stream.length());
if (static_cast<StreamKind>(stream.kind()) == StreamKind::StreamKind_ROW_INDEX) {
if (offset + length > fileLength) {
Comment thread
stiga-huang marked this conversation as resolved.
Outdated
std::stringstream msg;
msg << "Malformed RowIndex stream meta: streamOffset=" << offset
<< ", streamLength=" << length << ", fileLength=" << fileLength;
throw ParseError(msg.str());
}
std::unique_ptr<SeekableInputStream> pbStream =
createDecompressor(contents->compression,
std::unique_ptr<SeekableInputStream>
Expand Down Expand Up @@ -586,8 +592,15 @@ namespace orc {

void ReaderImpl::readMetadata() const {
uint64_t metadataSize = contents->postscript->metadatalength();
uint64_t metadataStart = fileLength - metadataSize
- contents->postscript->footerlength() - postscriptLength - 1;
uint64_t footerLength = contents->postscript->footerlength();
if (fileLength < metadataSize + footerLength + postscriptLength + 1) {
std::stringstream msg;
msg << "Invalid Metadata length: fileLength=" << fileLength
<< ", metadataLength=" << metadataSize << ", footerLength=" << footerLength
<< ", postscriptLength=" << postscriptLength;
throw ParseError(msg.str());
}
uint64_t metadataStart = fileLength - metadataSize - footerLength - postscriptLength - 1;
if (metadataSize != 0) {
std::unique_ptr<SeekableInputStream> pbStream =
createDecompressor(contents->compression,
Expand Down Expand Up @@ -798,6 +811,16 @@ namespace orc {
void RowReaderImpl::startNextStripe() {
reader.reset(); // ColumnReaders use lots of memory; free old memory first
currentStripeInfo = footer->stripes(static_cast<int>(currentStripe));
uint64_t fileLength = contents->stream->getLength();
if (currentStripeInfo.offset() + currentStripeInfo.indexlength() +
currentStripeInfo.datalength() + currentStripeInfo.footerlength() >= fileLength) {
std::stringstream msg;
msg << "Malformed StripeInformation at stripe index " << currentStripe << ": fileLength="
<< fileLength << ", StripeInfo=(offset=" << currentStripeInfo.offset() << ", indexLength="
<< currentStripeInfo.indexlength() << ", dataLength=" << currentStripeInfo.datalength()
<< ", footerLength=" << currentStripeInfo.footerlength() << ")";
throw ParseError(msg.str());
}
currentStripeFooter = getStripeFooter(currentStripeInfo, *contents.get());
rowsInCurrentStripe = currentStripeInfo.numberofrows();
const Timezone& writerTimezone =
Expand Down Expand Up @@ -889,6 +912,12 @@ namespace orc {

std::unique_ptr<proto::PostScript> postscript =
std::unique_ptr<proto::PostScript>(new proto::PostScript());
if (readSize < 1 + postscriptSize) {
std::stringstream msg;
msg << "Invalid ORC postscript length: " << postscriptSize << ", file length = "
<< stream->getLength();
throw ParseError(msg.str());
}
if (!postscript->ParseFromArray(ptr + readSize - 1 - postscriptSize,
static_cast<int>(postscriptSize))) {
throw ParseError("Failed to parse the postscript from " +
Expand Down Expand Up @@ -997,6 +1026,11 @@ namespace orc {
buffer.get(), postscriptLength));
uint64_t footerSize = contents->postscript->footerlength();
uint64_t tailSize = 1 + postscriptLength + footerSize;
if (tailSize >= fileLength) {
std::stringstream msg;
msg << "Invalid ORC tailSize=" << tailSize << ", fileLength=" << fileLength;
throw ParseError(msg.str());
}
uint64_t footerOffset;

if (tailSize > readSize) {
Expand Down
11 changes: 9 additions & 2 deletions c++/src/StripeStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ namespace orc {
if (stream.has_kind() &&
stream.kind() == kind &&
stream.column() == static_cast<uint64_t>(columnId)) {
uint64_t myBlock = shouldStream ? input.getNaturalReadSize():
stream.length();
uint64_t streamLength = stream.length();
uint64_t myBlock = shouldStream ? input.getNaturalReadSize(): streamLength;
if (offset + streamLength > input.getLength()) {
std::stringstream msg;
msg << "Malformed stream meta at stream index " << i
<< ": streamOffset=" << offset << ", streamLength=" << streamLength
<< ", fileLength=" << input.getLength();
throw ParseError(msg.str());
}
return createDecompressor(reader.getCompression(),
std::unique_ptr<SeekableInputStream>
(new SeekableFileInputStream
Expand Down