From 51f0ff7fb795b761dc857f7bec32f794abe74298 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Thu, 26 Dec 2024 09:54:50 +0800 Subject: [PATCH 1/4] opt: add debug log and more friendly error message --- src/dict/utils/indexedzip.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dict/utils/indexedzip.cc b/src/dict/utils/indexedzip.cc index c1aa4c60e..06f98207d 100644 --- a/src/dict/utils/indexedzip.cc +++ b/src/dict/utils/indexedzip.cc @@ -84,7 +84,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) return (size_t)zip.read( &data.front(), data.size() ) == data.size(); case ZipFile::Deflated: { - // Now do the deflation + // Decompress the data using the zlib library QByteArray compressedData = zip.read( header.compressedSize ); @@ -94,9 +94,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) data.resize( header.uncompressedSize ); - z_stream stream; - - memset( &stream, 0, sizeof( stream ) ); + z_stream stream = {}; stream.next_in = (Bytef *)compressedData.data(); stream.avail_in = compressedData.size(); @@ -108,8 +106,9 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) return false; } - if ( inflate( &stream, Z_FINISH ) != Z_STREAM_END ) { - qDebug( "Not zstream end!" ); + int ret = inflate( &stream, Z_FINISH ); + if ( ret != Z_STREAM_END ) { + qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out << "msg:" << (stream.msg ? stream.msg : "none"); data.clear(); From 62b9a99986c0bc11a423292dd99a76ea9f3eb04e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 26 Dec 2024 02:56:00 +0000 Subject: [PATCH 2/4] [autofix.ci] apply automated fixes --- src/dict/utils/indexedzip.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dict/utils/indexedzip.cc b/src/dict/utils/indexedzip.cc index 06f98207d..71b198814 100644 --- a/src/dict/utils/indexedzip.cc +++ b/src/dict/utils/indexedzip.cc @@ -108,7 +108,8 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) int ret = inflate( &stream, Z_FINISH ); if ( ret != Z_STREAM_END ) { - qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out << "msg:" << (stream.msg ? stream.msg : "none"); + qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out + << "msg:" << ( stream.msg ? stream.msg : "none" ); data.clear(); From 66d6fbe57e8abe03d484920f4f5d2425ade01077 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Thu, 26 Dec 2024 16:19:07 +0800 Subject: [PATCH 3/4] opt: check result of inflateEnd --- src/dict/utils/indexedzip.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dict/utils/indexedzip.cc b/src/dict/utils/indexedzip.cc index 71b198814..84f016a12 100644 --- a/src/dict/utils/indexedzip.cc +++ b/src/dict/utils/indexedzip.cc @@ -109,16 +109,26 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) int ret = inflate( &stream, Z_FINISH ); if ( ret != Z_STREAM_END ) { qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out - << "msg:" << ( stream.msg ? stream.msg : "none" ); + << "msg:" << ( stream.msg ? stream.msg : "none" ); data.clear(); - inflateEnd( &stream ); + int endRet = inflateEnd( &stream ); + if ( endRet != Z_OK ) { + qDebug() << "inflateEnd failed after inflate! msg:" << ( stream.msg ? stream.msg : "none" ); + } return false; } - inflateEnd( &stream ); + ret = inflateEnd( &stream ); + if ( ret != Z_OK ) { + qDebug() << "inflateEnd failed! msg:" << ( stream.msg ? stream.msg : "none" ); + + data.clear(); + + return false; + } return true; } From 8f06e7084ac90387427548f40bc028c3f776f807 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 03:44:11 +0000 Subject: [PATCH 4/4] [autofix.ci] apply automated fixes --- src/dict/utils/indexedzip.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dict/utils/indexedzip.cc b/src/dict/utils/indexedzip.cc index 84f016a12..c4a88597c 100644 --- a/src/dict/utils/indexedzip.cc +++ b/src/dict/utils/indexedzip.cc @@ -109,7 +109,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) int ret = inflate( &stream, Z_FINISH ); if ( ret != Z_STREAM_END ) { qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out - << "msg:" << ( stream.msg ? stream.msg : "none" ); + << "msg:" << ( stream.msg ? stream.msg : "none" ); data.clear();