mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #28543 from azat/bzip2-fix
Fix endless loop for truncated bzip2 archive
This commit is contained in:
commit
25a242fa68
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
# include <Common/config.h>
|
||||
#endif
|
||||
|
||||
#if USE_BROTLI
|
||||
#if USE_BZIP2
|
||||
# include <IO/Bzip2WriteBuffer.h>
|
||||
# include <bzlib.h> // Y_IGNORE
|
||||
|
||||
|
15
tests/queries/0_stateless/02022_bzip2_truncated.sh
Executable file
15
tests/queries/0_stateless/02022_bzip2_truncated.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user