Merge pull request #40482 from ClickHouse/Avogar-patch-1

Fix bug in HadoopSnappyReadBuffer
This commit is contained in:
Kruglov Pavel 2022-08-23 11:47:59 +02:00 committed by GitHub
commit 54ed9029b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 15 deletions

View File

@ -183,23 +183,28 @@ bool HadoopSnappyReadBuffer::nextImpl()
if (eof)
return false;
if (!in_available)
do
{
in->nextIfAtEnd();
in_available = in->buffer().end() - in->position();
in_data = in->position();
if (!in_available)
{
in->nextIfAtEnd();
in_available = in->buffer().end() - in->position();
in_data = in->position();
}
if (decoder->result == Status::NEEDS_MORE_INPUT && (!in_available || in->eof()))
{
throw Exception(String("hadoop snappy decode error:") + statusToString(decoder->result), ErrorCodes::SNAPPY_UNCOMPRESS_FAILED);
}
out_capacity = internal_buffer.size();
out_data = internal_buffer.begin();
decoder->result = decoder->readBlock(&in_available, &in_data, &out_capacity, &out_data);
in->position() = in->buffer().end() - in_available;
}
while (decoder->result == Status::NEEDS_MORE_INPUT);
if (decoder->result == Status::NEEDS_MORE_INPUT && (!in_available || in->eof()))
{
throw Exception(String("hadoop snappy decode error:") + statusToString(decoder->result), ErrorCodes::SNAPPY_UNCOMPRESS_FAILED);
}
out_capacity = internal_buffer.size();
out_data = internal_buffer.begin();
decoder->result = decoder->readBlock(&in_available, &in_data, &out_capacity, &out_data);
in->position() = in->buffer().end() - in_available;
working_buffer.resize(internal_buffer.size() - out_capacity);
if (decoder->result == Status::OK)

View File

@ -60,7 +60,8 @@ TEST(HadoopSnappyDecoder, repeatNeedMoreInput)
String output;
WriteBufferFromString out(output);
copyData(read_buffer, out);
out.finalize();
UInt128 hashcode = sipHash128(output.c_str(), output.size());
String hashcode_str = getHexUIntLowercase(hashcode);
ASSERT_EQ(hashcode_str, "593afe14f61866915cc00b8c7bd86046");
ASSERT_EQ(hashcode_str, "673e5b065186cec146789451c2a8f703");
}