aboutsummaryrefslogtreecommitdiff
path: root/C/XzDec.c
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /C/XzDec.c
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-24.05.tar.gz
7zip-24.05.tar.bz2
7zip-24.05.zip
24.0524.05
Diffstat (limited to 'C/XzDec.c')
-rw-r--r--C/XzDec.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/C/XzDec.c b/C/XzDec.c
index a5f7039..3d1c98e 100644
--- a/C/XzDec.c
+++ b/C/XzDec.c
@@ -1,5 +1,5 @@
1/* XzDec.c -- Xz Decode 1/* XzDec.c -- Xz Decode
22023-04-13 : Igor Pavlov : Public domain */ 22024-03-01 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
@@ -105,30 +105,32 @@ static SRes XzBcFilterState_SetProps(void *pp, const Byte *props, size_t propSiz
105 { 105 {
106 if (propSize != 1) 106 if (propSize != 1)
107 return SZ_ERROR_UNSUPPORTED; 107 return SZ_ERROR_UNSUPPORTED;
108 p->delta = (unsigned)props[0] + 1; 108 p->delta = (UInt32)props[0] + 1;
109 } 109 }
110 else 110 else
111 { 111 {
112 if (propSize == 4) 112 if (propSize == 4)
113 { 113 {
114 UInt32 v = GetUi32(props); 114 const UInt32 v = GetUi32(props);
115 switch (p->methodId) 115 switch (p->methodId)
116 { 116 {
117 case XZ_ID_PPC: 117 case XZ_ID_PPC:
118 case XZ_ID_ARM: 118 case XZ_ID_ARM:
119 case XZ_ID_SPARC: 119 case XZ_ID_SPARC:
120 case XZ_ID_ARM64: 120 case XZ_ID_ARM64:
121 if ((v & 3) != 0) 121 if (v & 3)
122 return SZ_ERROR_UNSUPPORTED; 122 return SZ_ERROR_UNSUPPORTED;
123 break; 123 break;
124 case XZ_ID_ARMT: 124 case XZ_ID_ARMT:
125 if ((v & 1) != 0) 125 case XZ_ID_RISCV:
126 if (v & 1)
126 return SZ_ERROR_UNSUPPORTED; 127 return SZ_ERROR_UNSUPPORTED;
127 break; 128 break;
128 case XZ_ID_IA64: 129 case XZ_ID_IA64:
129 if ((v & 0xF) != 0) 130 if (v & 0xf)
130 return SZ_ERROR_UNSUPPORTED; 131 return SZ_ERROR_UNSUPPORTED;
131 break; 132 break;
133 default: break;
132 } 134 }
133 p->ip = v; 135 p->ip = v;
134 } 136 }
@@ -151,12 +153,13 @@ static void XzBcFilterState_Init(void *pp)
151 153
152static const z7_Func_BranchConv g_Funcs_BranchConv_RISC_Dec[] = 154static const z7_Func_BranchConv g_Funcs_BranchConv_RISC_Dec[] =
153{ 155{
154 Z7_BRANCH_CONV_DEC(PPC), 156 Z7_BRANCH_CONV_DEC_2 (BranchConv_PPC),
155 Z7_BRANCH_CONV_DEC(IA64), 157 Z7_BRANCH_CONV_DEC_2 (BranchConv_IA64),
156 Z7_BRANCH_CONV_DEC(ARM), 158 Z7_BRANCH_CONV_DEC_2 (BranchConv_ARM),
157 Z7_BRANCH_CONV_DEC(ARMT), 159 Z7_BRANCH_CONV_DEC_2 (BranchConv_ARMT),
158 Z7_BRANCH_CONV_DEC(SPARC), 160 Z7_BRANCH_CONV_DEC_2 (BranchConv_SPARC),
159 Z7_BRANCH_CONV_DEC(ARM64) 161 Z7_BRANCH_CONV_DEC_2 (BranchConv_ARM64),
162 Z7_BRANCH_CONV_DEC_2 (BranchConv_RISCV)
160}; 163};
161 164
162static SizeT XzBcFilterStateBase_Filter_Dec(CXzBcFilterStateBase *p, Byte *data, SizeT size) 165static SizeT XzBcFilterStateBase_Filter_Dec(CXzBcFilterStateBase *p, Byte *data, SizeT size)
@@ -262,7 +265,7 @@ static SRes XzBcFilterState_Code2(void *pp,
262 265
263 266
264#define XZ_IS_SUPPORTED_FILTER_ID(id) \ 267#define XZ_IS_SUPPORTED_FILTER_ID(id) \
265 ((id) >= XZ_ID_Delta && (id) <= XZ_ID_ARM64) 268 ((id) >= XZ_ID_Delta && (id) <= XZ_ID_RISCV)
266 269
267SRes Xz_StateCoder_Bc_SetFromMethod_Func(IStateCoder *p, UInt64 id, 270SRes Xz_StateCoder_Bc_SetFromMethod_Func(IStateCoder *p, UInt64 id,
268 Xz_Func_BcFilterStateBase_Filter func, ISzAllocPtr alloc) 271 Xz_Func_BcFilterStateBase_Filter func, ISzAllocPtr alloc)
@@ -541,13 +544,12 @@ static SRes MixCoder_SetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 met
541{ 544{
542 IStateCoder *sc = &p->coders[coderIndex]; 545 IStateCoder *sc = &p->coders[coderIndex];
543 p->ids[coderIndex] = methodId; 546 p->ids[coderIndex] = methodId;
544 switch (methodId) 547 if (methodId == XZ_ID_LZMA2)
545 { 548 return Lzma2State_SetFromMethod(sc, outBuf, outBufSize, p->alloc);
546 case XZ_ID_LZMA2: return Lzma2State_SetFromMethod(sc, outBuf, outBufSize, p->alloc); 549#ifdef USE_SUBBLOCK
547 #ifdef USE_SUBBLOCK 550 if (methodId == XZ_ID_Subblock)
548 case XZ_ID_Subblock: return SbState_SetFromMethod(sc, p->alloc); 551 return SbState_SetFromMethod(sc, p->alloc);
549 #endif 552#endif
550 }
551 if (coderIndex == 0) 553 if (coderIndex == 0)
552 return SZ_ERROR_UNSUPPORTED; 554 return SZ_ERROR_UNSUPPORTED;
553 return Xz_StateCoder_Bc_SetFromMethod_Func(sc, methodId, 555 return Xz_StateCoder_Bc_SetFromMethod_Func(sc, methodId,
@@ -558,10 +560,8 @@ static SRes MixCoder_SetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 met
558static SRes MixCoder_ResetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 methodId, Byte *outBuf, size_t outBufSize) 560static SRes MixCoder_ResetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 methodId, Byte *outBuf, size_t outBufSize)
559{ 561{
560 IStateCoder *sc = &p->coders[coderIndex]; 562 IStateCoder *sc = &p->coders[coderIndex];
561 switch (methodId) 563 if (methodId == XZ_ID_LZMA2)
562 { 564 return Lzma2State_ResetOutBuf(sc, outBuf, outBufSize);
563 case XZ_ID_LZMA2: return Lzma2State_ResetOutBuf(sc, outBuf, outBufSize);
564 }
565 return SZ_ERROR_UNSUPPORTED; 565 return SZ_ERROR_UNSUPPORTED;
566} 566}
567 567
@@ -804,7 +804,7 @@ static BoolInt Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte
804} 804}
805 805
806#define READ_VARINT_AND_CHECK(buf, pos, size, res) \ 806#define READ_VARINT_AND_CHECK(buf, pos, size, res) \
807 { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \ 807 { const unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
808 if (s == 0) return SZ_ERROR_ARCHIVE; \ 808 if (s == 0) return SZ_ERROR_ARCHIVE; \
809 pos += s; } 809 pos += s; }
810 810
@@ -1034,7 +1034,7 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1034 SRes res; 1034 SRes res;
1035 1035
1036 ECoderFinishMode finishMode2 = finishMode; 1036 ECoderFinishMode finishMode2 = finishMode;
1037 BoolInt srcFinished2 = srcFinished; 1037 BoolInt srcFinished2 = (BoolInt)srcFinished;
1038 BoolInt destFinish = False; 1038 BoolInt destFinish = False;
1039 1039
1040 if (p->block.packSize != (UInt64)(Int64)-1) 1040 if (p->block.packSize != (UInt64)(Int64)-1)
@@ -1127,7 +1127,7 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1127 return SZ_OK; 1127 return SZ_OK;
1128 } 1128 }
1129 1129
1130 switch (p->state) 1130 switch ((int)p->state)
1131 { 1131 {
1132 case XZ_STATE_STREAM_HEADER: 1132 case XZ_STATE_STREAM_HEADER:
1133 { 1133 {
@@ -1172,15 +1172,15 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1172 p->state = XZ_STATE_STREAM_INDEX; 1172 p->state = XZ_STATE_STREAM_INDEX;
1173 break; 1173 break;
1174 } 1174 }
1175 p->blockHeaderSize = ((UInt32)p->buf[0] << 2) + 4; 1175 p->blockHeaderSize = ((unsigned)p->buf[0] << 2) + 4;
1176 break; 1176 break;
1177 } 1177 }
1178 1178
1179 if (p->pos != p->blockHeaderSize) 1179 if (p->pos != p->blockHeaderSize)
1180 { 1180 {
1181 UInt32 cur = p->blockHeaderSize - p->pos; 1181 unsigned cur = p->blockHeaderSize - p->pos;
1182 if (cur > srcRem) 1182 if (cur > srcRem)
1183 cur = (UInt32)srcRem; 1183 cur = (unsigned)srcRem;
1184 memcpy(p->buf + p->pos, src, cur); 1184 memcpy(p->buf + p->pos, src, cur);
1185 p->pos += cur; 1185 p->pos += cur;
1186 (*srcLen) += cur; 1186 (*srcLen) += cur;
@@ -1222,8 +1222,8 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1222 } 1222 }
1223 else 1223 else
1224 { 1224 {
1225 UInt32 checkSize = XzFlags_GetCheckSize(p->streamFlags); 1225 const unsigned checkSize = XzFlags_GetCheckSize(p->streamFlags);
1226 UInt32 cur = checkSize - p->pos; 1226 unsigned cur = checkSize - p->pos;
1227 if (cur != 0) 1227 if (cur != 0)
1228 { 1228 {
1229 if (srcRem == 0) 1229 if (srcRem == 0)
@@ -1232,7 +1232,7 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1232 return SZ_OK; 1232 return SZ_OK;
1233 } 1233 }
1234 if (cur > srcRem) 1234 if (cur > srcRem)
1235 cur = (UInt32)srcRem; 1235 cur = (unsigned)srcRem;
1236 memcpy(p->buf + p->pos, src, cur); 1236 memcpy(p->buf + p->pos, src, cur);
1237 p->pos += cur; 1237 p->pos += cur;
1238 (*srcLen) += cur; 1238 (*srcLen) += cur;
@@ -1321,9 +1321,9 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1321 1321
1322 case XZ_STATE_STREAM_FOOTER: 1322 case XZ_STATE_STREAM_FOOTER:
1323 { 1323 {
1324 UInt32 cur = XZ_STREAM_FOOTER_SIZE - p->pos; 1324 unsigned cur = XZ_STREAM_FOOTER_SIZE - p->pos;
1325 if (cur > srcRem) 1325 if (cur > srcRem)
1326 cur = (UInt32)srcRem; 1326 cur = (unsigned)srcRem;
1327 memcpy(p->buf + p->pos, src, cur); 1327 memcpy(p->buf + p->pos, src, cur);
1328 p->pos += cur; 1328 p->pos += cur;
1329 (*srcLen) += cur; 1329 (*srcLen) += cur;
@@ -1358,6 +1358,8 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
1358 } 1358 }
1359 1359
1360 case XZ_STATE_BLOCK: break; /* to disable GCC warning */ 1360 case XZ_STATE_BLOCK: break; /* to disable GCC warning */
1361
1362 default: return SZ_ERROR_FAIL;
1361 } 1363 }
1362 } 1364 }
1363 /* 1365 /*
@@ -1773,10 +1775,10 @@ static void XzDecMt_Callback_Parse(void *obj, unsigned coderIndex, CMtDecCallbac
1773 } 1775 }
1774 } 1776 }
1775 { 1777 {
1776 UInt64 packSize = block->packSize; 1778 const UInt64 packSize = block->packSize;
1777 UInt64 packSizeAligned = packSize + ((0 - (unsigned)packSize) & 3); 1779 const UInt64 packSizeAligned = packSize + ((0 - (unsigned)packSize) & 3);
1778 UInt32 checkSize = XzFlags_GetCheckSize(coder->dec.streamFlags); 1780 const unsigned checkSize = XzFlags_GetCheckSize(coder->dec.streamFlags);
1779 UInt64 blockPackSum = coder->inPreSize + packSizeAligned + checkSize; 1781 const UInt64 blockPackSum = coder->inPreSize + packSizeAligned + checkSize;
1780 // if (blockPackSum <= me->props.inBlockMax) 1782 // if (blockPackSum <= me->props.inBlockMax)
1781 // unpackBlockMaxSize 1783 // unpackBlockMaxSize
1782 { 1784 {
@@ -2381,7 +2383,7 @@ static SRes XzDecMt_Decode_ST(CXzDecMt *p
2381 if (tMode) 2383 if (tMode)
2382 { 2384 {
2383 XzDecMt_FreeOutBufs(p); 2385 XzDecMt_FreeOutBufs(p);
2384 tMode = MtDec_PrepareRead(&p->mtc); 2386 tMode = (BoolInt)MtDec_PrepareRead(&p->mtc);
2385 } 2387 }
2386 #endif 2388 #endif
2387 2389
@@ -2644,7 +2646,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle p,
2644 p->outSize = *outDataSize; 2646 p->outSize = *outDataSize;
2645 } 2647 }
2646 2648
2647 p->finishMode = finishMode; 2649 p->finishMode = (BoolInt)finishMode;
2648 2650
2649 // p->outSize = 457; p->outSize_Defined = True; p->finishMode = False; // for test 2651 // p->outSize = 457; p->outSize_Defined = True; p->finishMode = False; // for test
2650 2652