Merge pull request #28543 from azat/bzip2-fix

Fix endless loop for truncated bzip2 archive
This commit is contained in:
Maksim Kita 2021-09-03 11:41:42 +03:00 committed by GitHub
commit 25a242fa68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View File

@ -12,6 +12,7 @@ namespace DB
namespace ErrorCodes
{
extern const int BZIP2_STREAM_DECODER_FAILED;
extern const int UNEXPECTED_END_OF_FILE;
}
@ -90,6 +91,12 @@ bool Bzip2ReadBuffer::nextImpl()
"bzip2 stream decoder failed: error code: {}",
ret);
if (in->eof())
{
eof = true;
throw Exception(ErrorCodes::UNEXPECTED_END_OF_FILE, "Unexpected end of bzip2 archive");
}
return true;
}
}

View File

@ -2,7 +2,7 @@
# include <Common/config.h>
#endif
#if USE_BROTLI
#if USE_BZIP2
# include <IO/Bzip2WriteBuffer.h>
# include <bzlib.h> // Y_IGNORE

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
tmp_path=$(mktemp "$CURDIR/02022_bzip2_truncate.XXXXXX.bz2")
trap 'rm -f $tmp_path' EXIT
${CLICKHOUSE_LOCAL} -q "SELECT * FROM numbers(1e6) FORMAT TSV" | bzip2 > "$tmp_path"
truncate -s10000 "$tmp_path"
# just ensure that it will exit eventually
${CLICKHOUSE_LOCAL} -q "SELECT count() FROM file('$tmp_path', 'TSV', 'n UInt64') FORMAT Null" >& /dev/null
exit 0