@@ -22,7 +22,7 @@ constexpr ui32 LegacyMagicNumber = 0x184C2102U;
2222constexpr size_t LegacyBlockSize = 8_MB;
2323constexpr size_t FrameMaxBlockSize = 4_MB;
2424
25- void WriteLE32 (void * p, ui32 value32)
25+ void WriteLE32 (void * p, ui32 value32)
2626{
2727 const auto dstPtr = static_cast <unsigned char *>(p);
2828 dstPtr[0 ] = (unsigned char )value32;
@@ -31,7 +31,7 @@ void WriteLE32 (void* p, ui32 value32)
3131 dstPtr[3 ] = (unsigned char )(value32 >> 24U );
3232}
3333
34- ui32 ReadLE32 (const void * s) {
34+ ui32 ReadLE32 (const void * s) {
3535 const auto srcPtr = static_cast <const unsigned char *>(s);
3636 ui32 value32 = srcPtr[0 ];
3737 value32 += (ui32)srcPtr[1 ] << 8U ;
@@ -112,29 +112,35 @@ bool TReadBuffer::nextImpl() {
112112}
113113
114114size_t TReadBuffer::DecompressFrame () {
115- if (NextToLoad > InBuffer.size ()) {
116- InBuffer.resize (NextToLoad);
117- }
118-
119- if (Pos >= Remaining) {
120- for (auto toRead = NextToLoad; toRead > 0U ;) {
121- const auto sizeCheck = Source.read (InBuffer.data () + NextToLoad - toRead, toRead);
122- YQL_ENSURE (sizeCheck > 0U && sizeCheck <= toRead, " Cannot access compressed block." );
123- toRead -= sizeCheck;
115+ while (NextToLoad) {
116+ if (NextToLoad > InBuffer.size ()) {
117+ InBuffer.resize (NextToLoad);
124118 }
125119
126- Pos = 0ULL ;
127- Remaining = NextToLoad;
128- }
120+ if (Pos >= Remaining) {
121+ for (auto toRead = NextToLoad; toRead > 0U ;) {
122+ const auto sizeCheck = Source.read (InBuffer.data () + NextToLoad - toRead, toRead);
123+ YQL_ENSURE (sizeCheck > 0U && sizeCheck <= toRead, " Cannot access compressed block." );
124+ toRead -= sizeCheck;
125+ }
126+
127+ Pos = 0ULL ;
128+ Remaining = NextToLoad;
129+ }
129130
130- if (Pos < Remaining) {
131131 auto decodedBytes = OutBuffer.size ();
132- NextToLoad = LZ4F_decompress_usingDict (Ctx, OutBuffer.data (), &decodedBytes, InBuffer.data () + Pos, &Remaining, nullptr , 0ULL , nullptr );
133- YQL_ENSURE (!LZ4F_isError (NextToLoad), " Decompression error: " << LZ4F_getErrorName (NextToLoad));
134- Pos += Remaining;
132+ while (Pos < Remaining || (decodedBytes == OutBuffer.size ())) {
133+ decodedBytes = OutBuffer.size ();
134+ NextToLoad = LZ4F_decompress_usingDict (Ctx, OutBuffer.data (), &decodedBytes, InBuffer.data () + Pos, &Remaining, nullptr , 0ULL , nullptr );
135+ YQL_ENSURE (!LZ4F_isError (NextToLoad), " Decompression error: " << LZ4F_getErrorName (NextToLoad));
136+ Pos += Remaining;
137+
138+ if (decodedBytes)
139+ return decodedBytes;
135140
136- if (decodedBytes)
137- return decodedBytes;
141+ if (!NextToLoad)
142+ return decodedBytes;
143+ }
138144 }
139145
140146 return 0ULL ;
0 commit comments