{"id":2175801,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2175801/?format=json","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.0/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20251218232255.3934258-7-trini@konsulko.com>","date":"2025-12-18T23:10:18","name":"[RFC,6/9] lzma: Update 18.06 -> 21.07","commit_ref":null,"pull_url":null,"state":"rfc","archived":false,"hash":"e90de4553646b5bf48f48b200a2f7b024b9db0fb","submitter":{"id":65875,"url":"http://patchwork.ozlabs.org/api/1.0/people/65875/?format=json","name":"Tom Rini","email":"trini@konsulko.com"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/1.0/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20251218232255.3934258-7-trini@konsulko.com/mbox/","series":[{"id":485929,"url":"http://patchwork.ozlabs.org/api/1.0/series/485929/?format=json","date":"2025-12-18T23:10:12","name":"Update lzma to current version of LZMA SDK","version":1,"mbox":"http://patchwork.ozlabs.org/series/485929/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2175801/checks/","tags":{},"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=konsulko.com header.i=@konsulko.com header.a=rsa-sha256\n header.s=google header.b=YqZow5z8;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=konsulko.com","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=konsulko.com header.i=@konsulko.com\n header.b=\"YqZow5z8\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=konsulko.com","phobos.denx.de;\n spf=pass smtp.mailfrom=trini@konsulko.com"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dXRZ90sZGz1xty\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 19 Dec 2025 10:24:01 +1100 (AEDT)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id E05A0836A3;\n\tFri, 19 Dec 2025 00:23:13 +0100 (CET)","by phobos.denx.de (Postfix, from userid 109)\n id 01790836A3; Fri, 19 Dec 2025 00:23:09 +0100 (CET)","from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com\n [IPv6:2607:f8b0:4864:20::22b])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id C7A3A835FD\n for <u-boot@lists.denx.de>; Fri, 19 Dec 2025 00:23:05 +0100 (CET)","by mail-oi1-x22b.google.com with SMTP id\n 5614622812f47-4557e6303a5so428481b6e.3\n for <u-boot@lists.denx.de>; Thu, 18 Dec 2025 15:23:05 -0800 (PST)","from bill-the-cat.. (fixed-189-203-103-235.totalplay.net.\n [189.203.103.235]) by smtp.gmail.com with ESMTPSA id\n 5614622812f47-457b3cc0928sm295333b6e.10.2025.12.18.15.23.03\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 18 Dec 2025 15:23:03 -0800 (PST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,\n SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=konsulko.com; s=google; t=1766100184; x=1766704984; darn=lists.denx.de;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=M9Sioy4HDuo4JSGte7vkXl87videLjkxxuUQdFDKCv4=;\n b=YqZow5z8pq2+wPyA/PdSHz/BwjXynPwHSmcUzA7hM0jILNc4OZqZI5bNKInlKtW0b/\n t3PFNySfxGQXhv3mjerO0ICEhBF7KxYoloWDcis+w62p4wEajnU8pYwxKr+bErw8Hwek\n VpNaUv91+cwxSYsmRDTMxsJ/VuX2vbhFow5O0=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1766100184; x=1766704984;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=M9Sioy4HDuo4JSGte7vkXl87videLjkxxuUQdFDKCv4=;\n b=ub1o/Vw/XHrtOTIwRKdd+VrhK1tBsswuh77TnQ3k8ghLB0Vv7tTUYEasa8n8b6F4Ta\n o5JImz3PCbLtjoeUA3OcXgp7nUBWnuQxWP9xnNyMe1tHNVvqbMCfCmzuBo1PCrF9BPBP\n +JQBzyBm4Km4YP3YbP5FKtKtmXZwhjH/pdlr/gdtuDCAdN0X9pFoAAdUJxlUDqYhqASC\n r34iHv/ObiV585FEnjyPDkmBe7lS7jdFyCT1Lk/WmKNHuJWMpfDRFQ/+Ct1W3yLtdUGZ\n z31VsH3GCB4r+yxoKZGKacAP110hHg4N6H6HPOthBx5nBNtTklEucWBGpV06yUgz/Fkm\n OxqA==","X-Gm-Message-State":"AOJu0Yz5VoGzynIuib2v9qyN9dJZrbi6UBuDYPZe2Gw07D2+e/5oftdC\n eKanBdY/To+BKonfLr9tJxm1Vl8bVYiFEu8QOE6qVhJoq5mNM2x+/HAjhWCT97yT/8MGzHNBkrC\n qnV6w7wA=","X-Gm-Gg":"AY/fxX7b20qaF76HatKKVobIZOoc5M5cLqkrfU1T7HGlb51S+SI3OXvMol+k0/dhAmE\n qqpOizbQmsLZMQL1cP0hvLuDkNSPr2YVPrs5394kbMPWpj3iC++6hJgYesXuoaesiG0bM1B0TaX\n D6zM91Fz0TIjX/au5MGA3pmP+IKUMJ/0n7QH5q6Ou0x/IBufKDc4+aKpM8JBvxiHffs75cBEspc\n 4E7Si5OjAeeF/JZuzwd8SS2aTwQqezfq1I5ibCFNaA46ogr8yJxZx0JxRL2xZxiyKWyMhn7Jynh\n BU8vtqON5vfMAz7aXs2Kzv4F/2s6i5EZ2aT3lFLJeioerxCQanXmNxdSvnl8C1WUdv7uKRjx//M\n cczT7v7q4UU5BgIteSlFA2ynaOlaNfJO9kOqV7p/kOGcp9WdSZUbkLLXnky54nzZxzM/tPklbNr\n 3yjD1O87WtTzXdDiSPOFLZ8xMeQn35/s2bEgrvRzdhRabrWEd5SCBErq2pTYn5wNI=","X-Google-Smtp-Source":"\n AGHT+IH1bNWq40UnGTetLwgACRTTi4hcr7UwJhdKgjHjv7GSb3YT/KCkkK9JmwlboPXqnBdcM5g/hw==","X-Received":"by 2002:a05:6808:bc7:b0:450:4628:e3f0 with SMTP id\n 5614622812f47-457b221dec8mr661719b6e.36.1766100184324;\n Thu, 18 Dec 2025 15:23:04 -0800 (PST)","From":"Tom Rini <trini@konsulko.com>","To":"u-boot@lists.denx.de","Cc":"Darek <x64x6a@gmail.com>","Subject":"[RFC PATCH 6/9] lzma: Update 18.06 -> 21.07","Date":"Thu, 18 Dec 2025 17:10:18 -0600","Message-ID":"<20251218232255.3934258-7-trini@konsulko.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20251218232255.3934258-1-trini@konsulko.com>","References":"<20251218232255.3934258-1-trini@konsulko.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Of note, add guards around TEXT macro and LONG typedef, both are unused\nin the code but cause problems on MIPS.\n\nSigned-off-by: Tom Rini <trini@konsulko.com>\n---\n lib/lzma/7zTypes.h  | 192 +++++++++++++++++++--\n lib/lzma/Compiler.h |  12 +-\n lib/lzma/LzmaDec.c  | 412 +++++++++++++++++++++++++++++++-------------\n lib/lzma/LzmaDec.h  |   4 +-\n 4 files changed, 482 insertions(+), 138 deletions(-)","diff":"diff --git a/lib/lzma/7zTypes.h b/lib/lzma/7zTypes.h\nindex 65b3af63c751..0b1fbb637793 100644\n--- a/lib/lzma/7zTypes.h\n+++ b/lib/lzma/7zTypes.h\n@@ -1,11 +1,13 @@\n /* 7zTypes.h -- Basic types\n-2018-08-04 : Igor Pavlov : Public domain */\n+2021-12-25 : Igor Pavlov : Public domain */\n \n #ifndef __7Z_TYPES_H\n #define __7Z_TYPES_H\n \n #ifdef _WIN32\n /* #include <windows.h> */\n+#else\n+#include <errno.h>\n #endif\n \n #include <stddef.h>\n@@ -43,18 +45,118 @@ EXTERN_C_BEGIN\n typedef int SRes;\n \n \n+#ifdef _MSC_VER\n+  #if _MSC_VER > 1200\n+    #define MY_ALIGN(n) __declspec(align(n))\n+  #else\n+    #define MY_ALIGN(n)\n+  #endif\n+#else\n+  #define MY_ALIGN(n) __attribute__ ((aligned(n)))\n+#endif\n+\n+\n #ifdef _WIN32\n \n /* typedef DWORD WRes; */\n typedef unsigned WRes;\n #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)\n \n-#else\n+// #define MY_HRES_ERROR__INTERNAL_ERROR  MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)\n+\n+#else // _WIN32\n \n+// #define ENV_HAVE_LSTAT\n typedef int WRes;\n-#define MY__FACILITY_WIN32 7\n-#define MY__FACILITY__WRes MY__FACILITY_WIN32\n-#define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))\n+\n+// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT\n+#define MY__FACILITY_ERRNO  0x800\n+#define MY__FACILITY_WIN32  7\n+#define MY__FACILITY__WRes  MY__FACILITY_ERRNO\n+\n+#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \\\n+          ( (HRESULT)(x) & 0x0000FFFF) \\\n+          | (MY__FACILITY__WRes << 16)  \\\n+          | (HRESULT)0x80000000 ))\n+\n+#define MY_SRes_HRESULT_FROM_WRes(x) \\\n+  ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))\n+\n+// we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)\n+#define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)\n+\n+/*\n+#define ERROR_FILE_NOT_FOUND             2L\n+#define ERROR_ACCESS_DENIED              5L\n+#define ERROR_NO_MORE_FILES              18L\n+#define ERROR_LOCK_VIOLATION             33L\n+#define ERROR_FILE_EXISTS                80L\n+#define ERROR_DISK_FULL                  112L\n+#define ERROR_NEGATIVE_SEEK              131L\n+#define ERROR_ALREADY_EXISTS             183L\n+#define ERROR_DIRECTORY                  267L\n+#define ERROR_TOO_MANY_POSTS             298L\n+\n+#define ERROR_INTERNAL_ERROR             1359L\n+#define ERROR_INVALID_REPARSE_DATA       4392L\n+#define ERROR_REPARSE_TAG_INVALID        4393L\n+#define ERROR_REPARSE_TAG_MISMATCH       4394L\n+*/\n+\n+// we use errno equivalents for some WIN32 errors:\n+\n+#define ERROR_INVALID_PARAMETER     EINVAL\n+#define ERROR_INVALID_FUNCTION      EINVAL\n+#define ERROR_ALREADY_EXISTS        EEXIST\n+#define ERROR_FILE_EXISTS           EEXIST\n+#define ERROR_PATH_NOT_FOUND        ENOENT\n+#define ERROR_FILE_NOT_FOUND        ENOENT\n+#define ERROR_DISK_FULL             ENOSPC\n+// #define ERROR_INVALID_HANDLE        EBADF\n+\n+// we use FACILITY_WIN32 for errors that has no errno equivalent\n+// Too many posts were made to a semaphore.\n+#define ERROR_TOO_MANY_POSTS        ((HRESULT)0x8007012AL)\n+#define ERROR_INVALID_REPARSE_DATA  ((HRESULT)0x80071128L)\n+#define ERROR_REPARSE_TAG_INVALID   ((HRESULT)0x80071129L)\n+\n+// if (MY__FACILITY__WRes != FACILITY_WIN32),\n+// we use FACILITY_WIN32 for COM errors:\n+#define E_OUTOFMEMORY               ((HRESULT)0x8007000EL)\n+#define E_INVALIDARG                ((HRESULT)0x80070057L)\n+#define MY__E_ERROR_NEGATIVE_SEEK   ((HRESULT)0x80070083L)\n+\n+/*\n+// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:\n+#define E_OUTOFMEMORY             MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)\n+#define E_INVALIDARG              MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)\n+#define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)\n+*/\n+\n+// gcc / clang : (sizeof(long) == sizeof(void*)) in 32/64 bits\n+typedef          long INT_PTR;\n+typedef unsigned long UINT_PTR;\n+\n+#ifndef __UBOOT__\n+#define TEXT(quote) quote\n+#endif\n+\n+#define FILE_ATTRIBUTE_READONLY       0x0001\n+#define FILE_ATTRIBUTE_HIDDEN         0x0002\n+#define FILE_ATTRIBUTE_SYSTEM         0x0004\n+#define FILE_ATTRIBUTE_DIRECTORY      0x0010\n+#define FILE_ATTRIBUTE_ARCHIVE        0x0020\n+#define FILE_ATTRIBUTE_DEVICE         0x0040\n+#define FILE_ATTRIBUTE_NORMAL         0x0080\n+#define FILE_ATTRIBUTE_TEMPORARY      0x0100\n+#define FILE_ATTRIBUTE_SPARSE_FILE    0x0200\n+#define FILE_ATTRIBUTE_REPARSE_POINT  0x0400\n+#define FILE_ATTRIBUTE_COMPRESSED     0x0800\n+#define FILE_ATTRIBUTE_OFFLINE        0x1000\n+#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000\n+#define FILE_ATTRIBUTE_ENCRYPTED      0x4000\n+\n+#define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000   /* trick for Unix */\n \n #endif\n \n@@ -63,6 +165,10 @@ typedef int WRes;\n #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\n #endif\n \n+#ifndef RINOK_WRes\n+#define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; }\n+#endif\n+\n typedef unsigned char Byte;\n typedef short Int16;\n typedef unsigned short UInt16;\n@@ -75,6 +181,42 @@ typedef int Int32;\n typedef unsigned int UInt32;\n #endif\n \n+\n+#ifndef _WIN32\n+\n+typedef int INT;\n+typedef Int32 INT32;\n+typedef unsigned int UINT;\n+typedef UInt32 UINT32;\n+#ifndef __UBOOT__\n+typedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility\n+#endif\n+typedef UINT32 ULONG;\n+\n+#undef DWORD\n+typedef UINT32 DWORD;\n+\n+#define VOID void\n+\n+#define HRESULT LONG\n+\n+typedef void *LPVOID;\n+// typedef void VOID;\n+// typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;\n+// gcc / clang on Unix  : sizeof(long==sizeof(void*) in 32 or 64 bits)\n+typedef          long  INT_PTR;\n+typedef unsigned long  UINT_PTR;\n+typedef          long  LONG_PTR;\n+typedef unsigned long  DWORD_PTR;\n+\n+typedef size_t SIZE_T;\n+\n+#endif //  _WIN32\n+\n+\n+#define MY_HRES_ERROR__INTERNAL_ERROR  ((HRESULT)0x8007054FL)\n+\n+\n #ifdef _SZ_NO_INT_64\n \n /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\n@@ -128,25 +270,37 @@ typedef int BoolInt;\n #define MY_CDECL __cdecl\n #define MY_FAST_CALL __fastcall\n \n-#else\n+#else //  _MSC_VER\n \n+#if (defined(__GNUC__) && (__GNUC__ >= 4)) \\\n+    || (defined(__clang__) && (__clang_major__ >= 4)) \\\n+    || defined(__INTEL_COMPILER) \\\n+    || defined(__xlC__)\n+#define MY_NO_INLINE __attribute__((noinline))\n+// #define MY_FORCE_INLINE __attribute__((always_inline)) inline\n+#else\n #define MY_NO_INLINE\n+#endif\n+\n #define MY_FORCE_INLINE\n-#define MY_CDECL\n-#define MY_FAST_CALL\n \n-/* inline keyword : for C++ / C99 */\n \n-/* GCC, clang: */\n-/*\n-#if defined (__GNUC__) && (__GNUC__ >= 4)\n-#define MY_FORCE_INLINE __attribute__((always_inline))\n-#define MY_NO_INLINE __attribute__((noinline))\n-#endif\n-*/\n+#define MY_CDECL\n \n+#if  defined(_M_IX86) \\\n+  || defined(__i386__)\n+// #define MY_FAST_CALL __attribute__((fastcall))\n+// #define MY_FAST_CALL __attribute__((cdecl))\n+#define MY_FAST_CALL\n+#elif defined(MY_CPU_AMD64)\n+// #define MY_FAST_CALL __attribute__((ms_abi))\n+#define MY_FAST_CALL\n+#else\n+#define MY_FAST_CALL\n #endif\n \n+#endif //  _MSC_VER\n+\n \n /* The following interfaces use first parameter as pointer to structure */\n \n@@ -335,12 +489,11 @@ struct ISzAlloc\n     GCC 4.8.1 : classes with non-public variable members\"\n */\n \n-#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))\n-\n+#define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))\n \n #endif\n \n-#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))\n+#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))\n \n /*\n #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)\n@@ -353,6 +506,7 @@ struct ISzAlloc\n */\n \n \n+#define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a))\n \n #ifdef _WIN32\n \ndiff --git a/lib/lzma/Compiler.h b/lib/lzma/Compiler.h\nindex 0cc409d8a864..a9816fa5ad01 100644\n--- a/lib/lzma/Compiler.h\n+++ b/lib/lzma/Compiler.h\n@@ -1,9 +1,13 @@\n /* Compiler.h\n-2017-04-03 : Igor Pavlov : Public domain */\n+2021-01-05 : Igor Pavlov : Public domain */\n \n #ifndef __7Z_COMPILER_H\n #define __7Z_COMPILER_H\n \n+  #ifdef __clang__\n+    #pragma clang diagnostic ignored \"-Wunused-private-field\"\n+  #endif\n+\n #ifdef _MSC_VER\n \n   #ifdef UNDER_CE\n@@ -25,6 +29,12 @@\n     #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information\n   #endif\n \n+  #ifdef __clang__\n+    #pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n+    #pragma clang diagnostic ignored \"-Wmicrosoft-exception-spec\"\n+    // #pragma clang diagnostic ignored \"-Wreserved-id-macro\"\n+  #endif\n+\n #endif\n \n #define UNUSED_VAR(x) (void)x;\ndiff --git a/lib/lzma/LzmaDec.c b/lib/lzma/LzmaDec.c\nindex 3319c7cf4938..a27f3c3b42a3 100644\n--- a/lib/lzma/LzmaDec.c\n+++ b/lib/lzma/LzmaDec.c\n@@ -1,5 +1,5 @@\n /* LzmaDec.c -- LZMA Decoder\n-2018-07-04 : Igor Pavlov : Public domain */\n+2021-04-01 : Igor Pavlov : Public domain */\n \n #include \"Precomp.h\"\n \n@@ -15,10 +15,12 @@\n \n #define kNumBitModelTotalBits 11\n #define kBitModelTotal (1 << kNumBitModelTotalBits)\n-#define kNumMoveBits 5\n \n #define RC_INIT_SIZE 5\n \n+#ifndef _LZMA_DEC_OPT\n+\n+#define kNumMoveBits 5\n #define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\n \n #define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)\n@@ -64,9 +66,10 @@\n   probLit = prob + (offs + bit + symbol); \\\n   GET_BIT2(probLit, symbol, offs ^= bit; , ;)\n \n+#endif // _LZMA_DEC_OPT\n \n \n-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\n+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_INPUT_EOF; range <<= 8; code = (code << 8) | (*buf++); }\n \n #define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)\n #define UPDATE_0_CHECK range = bound;\n@@ -116,6 +119,9 @@\n #define kMatchMinLen 2\n #define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)\n \n+#define kMatchSpecLen_Error_Data (1 << 9)\n+#define kMatchSpecLen_Error_Fail (kMatchSpecLen_Error_Data - 1)\n+\n /* External ASM code needs same CLzmaProb array layout. So don't change it. */\n \n /* (probs_1664) is faster and better for code size at some platforms */\n@@ -168,10 +174,12 @@\n \n /*\n p->remainLen : shows status of LZMA decoder:\n-    < kMatchSpecLenStart : normal remain\n-    = kMatchSpecLenStart : finished\n-    = kMatchSpecLenStart + 1 : need init range coder\n-    = kMatchSpecLenStart + 2 : need init range coder and state\n+    < kMatchSpecLenStart  : the number of bytes to be copied with (p->rep0) offset\n+    = kMatchSpecLenStart  : the LZMA stream was finished with end mark\n+    = kMatchSpecLenStart + 1  : need init range coder\n+    = kMatchSpecLenStart + 2  : need init range coder and state\n+    = kMatchSpecLen_Error_Fail                : Internal Code Failure\n+    = kMatchSpecLen_Error_Data + [0 ... 273]  : LZMA Data Error\n */\n \n /* ---------- LZMA_DECODE_REAL ---------- */\n@@ -190,23 +198,31 @@ In:\n   {\n     LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.\n     So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol\n-    is not END_OF_PAYALOAD_MARKER, then function returns error code.\n+    is not END_OF_PAYALOAD_MARKER, then the function doesn't write any byte to dictionary,\n+    the function returns SZ_OK, and the caller can use (p->remainLen) and (p->reps[0]) later.\n   }\n \n Processing:\n-  first LZMA symbol will be decoded in any case\n-  All checks for limits are at the end of main loop,\n-  It will decode new LZMA-symbols while (p->buf < bufLimit && dicPos < limit),\n+  The first LZMA symbol will be decoded in any case.\n+  All main checks for limits are at the end of main loop,\n+  It decodes additional LZMA-symbols while (p->buf < bufLimit && dicPos < limit),\n   RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.\n+  But if (p->buf < bufLimit), the caller provided at least (LZMA_REQUIRED_INPUT_MAX + 1) bytes for\n+  next iteration  before limit (bufLimit + LZMA_REQUIRED_INPUT_MAX),\n+  that is enough for worst case LZMA symbol with one additional RangeCoder normalization for one bit.\n+  So that function never reads bufLimit [LZMA_REQUIRED_INPUT_MAX] byte.\n \n Out:\n   RangeCoder is normalized\n   Result:\n     SZ_OK - OK\n-    SZ_ERROR_DATA - Error\n-  p->remainLen:\n-    < kMatchSpecLenStart : normal remain\n-    = kMatchSpecLenStart : finished\n+      p->remainLen:\n+        < kMatchSpecLenStart : the number of bytes to be copied with (p->reps[0]) offset\n+        = kMatchSpecLenStart : the LZMA stream was finished with end mark\n+\n+    SZ_ERROR_DATA - error, when the MATCH-Symbol refers out of dictionary\n+      p->remainLen : undefined\n+      p->reps[*]    : undefined\n */\n \n \n@@ -322,11 +338,6 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit\n       else\n       {\n         UPDATE_1(prob);\n-        /*\n-        // that case was checked before with kBadRepCode\n-        if (checkDicSize == 0 && processedPos == 0)\n-          return SZ_ERROR_DATA;\n-        */\n         prob = probs + IsRepG0 + state;\n         IF_BIT_0(prob)\n         {\n@@ -335,6 +346,13 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit\n           IF_BIT_0(prob)\n           {\n             UPDATE_0(prob);\n+\n+            // that case was checked before with kBadRepCode\n+            // if (checkDicSize == 0 && processedPos == 0) { len = kMatchSpecLen_Error_Data + 1; break; }\n+            // The caller doesn't allow (dicPos == limit) case here\n+            // so we don't need the following check:\n+            // if (dicPos == limit) { state = state < kNumLitStates ? 9 : 11; len = 1; break; }\n+\n             dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\n             dicPos++;\n             processedPos++;\n@@ -524,8 +542,10 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit\n         state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\n         if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))\n         {\n-          p->dicPos = dicPos;\n-          return SZ_ERROR_DATA;\n+          len += kMatchSpecLen_Error_Data + kMatchMinLen;\n+          // len = kMatchSpecLen_Error_Data;\n+          // len += kMatchMinLen;\n+          break;\n         }\n       }\n \n@@ -538,8 +558,13 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit\n \n         if ((rem = limit - dicPos) == 0)\n         {\n-          p->dicPos = dicPos;\n-          return SZ_ERROR_DATA;\n+          /*\n+          We stop decoding and return SZ_OK, and we can resume decoding later.\n+          Any error conditions can be tested later in caller code.\n+          For more strict mode we can stop decoding with error\n+          // len += kMatchSpecLen_Error_Data;\n+          */\n+          break;\n         }\n \n         curLen = ((rem < len) ? (unsigned)rem : len);\n@@ -580,7 +605,7 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit\n   p->buf = buf;\n   p->range = range;\n   p->code = code;\n-  p->remainLen = (UInt32)len;\n+  p->remainLen = (UInt32)len; // & (kMatchSpecLen_Error_Data - 1); // we can write real length for error matches too.\n   p->dicPos = dicPos;\n   p->processedPos = processedPos;\n   p->reps[0] = rep0;\n@@ -588,40 +613,61 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit\n   p->reps[2] = rep2;\n   p->reps[3] = rep3;\n   p->state = (UInt32)state;\n-\n+  if (len >= kMatchSpecLen_Error_Data)\n+    return SZ_ERROR_DATA;\n   return SZ_OK;\n }\n #endif\n \n+\n+\n static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\n {\n-  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\n+  unsigned len = (unsigned)p->remainLen;\n+  if (len == 0 /* || len >= kMatchSpecLenStart */)\n+    return;\n   {\n-    Byte *dic = p->dic;\n     SizeT dicPos = p->dicPos;\n-    SizeT dicBufSize = p->dicBufSize;\n-    unsigned len = (unsigned)p->remainLen;\n-    SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */\n-    SizeT rem = limit - dicPos;\n-    if (rem < len)\n-      len = (unsigned)(rem);\n+    Byte *dic;\n+    SizeT dicBufSize;\n+    SizeT rep0;   /* we use SizeT to avoid the BUG of VC14 for AMD64 */\n+    {\n+      SizeT rem = limit - dicPos;\n+      if (rem < len)\n+      {\n+        len = (unsigned)(rem);\n+        if (len == 0)\n+          return;\n+      }\n+    }\n \n     if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\n       p->checkDicSize = p->prop.dicSize;\n \n     p->processedPos += (UInt32)len;\n     p->remainLen -= (UInt32)len;\n-    while (len != 0)\n+    dic = p->dic;\n+    rep0 = p->reps[0];\n+    dicBufSize = p->dicBufSize;\n+    do\n     {\n-      len--;\n       dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\n       dicPos++;\n     }\n+    while (--len);\n     p->dicPos = dicPos;\n   }\n }\n \n \n+/*\n+At staring of new stream we have one of the following symbols:\n+  - Literal        - is allowed\n+  - Non-Rep-Match  - is allowed only if it's end marker symbol\n+  - Rep-Match      - is not allowed\n+We use early check of (RangeCoder:Code) over kBadRepCode to simplify main decoding code\n+*/\n+\n #define kRange0 0xFFFFFFFF\n #define kBound0 ((kRange0 >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1))\n #define kBadRepCode (kBound0 + (((kRange0 - kBound0) >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1)))\n@@ -629,69 +675,77 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\n   #error Stop_Compiling_Bad_LZMA_Check\n #endif\n \n-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\n-{\n-  do\n-  {\n-    SizeT limit2 = limit;\n-    if (p->checkDicSize == 0)\n-    {\n-      UInt32 rem = p->prop.dicSize - p->processedPos;\n-      if (limit - p->dicPos > rem)\n-        limit2 = p->dicPos + rem;\n \n-      if (p->processedPos == 0)\n-        if (p->code >= kBadRepCode)\n-          return SZ_ERROR_DATA;\n-    }\n+/*\n+LzmaDec_DecodeReal2():\n+  It calls LZMA_DECODE_REAL() and it adjusts limit according (p->checkDicSize).\n \n-    RINOK(LZMA_DECODE_REAL(p, limit2, bufLimit));\n+We correct (p->checkDicSize) after LZMA_DECODE_REAL() and in LzmaDec_WriteRem(),\n+and we support the following state of (p->checkDicSize):\n+  if (total_processed < p->prop.dicSize) then\n+  {\n+    (total_processed == p->processedPos)\n+    (p->checkDicSize == 0)\n+  }\n+  else\n+    (p->checkDicSize == p->prop.dicSize)\n+*/\n \n+static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\n+{\n+  if (p->checkDicSize == 0)\n+  {\n+    UInt32 rem = p->prop.dicSize - p->processedPos;\n+    if (limit - p->dicPos > rem)\n+      limit = p->dicPos + rem;\n+  }\n+  {\n+    int res = LZMA_DECODE_REAL(p, limit, bufLimit);\n     if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)\n       p->checkDicSize = p->prop.dicSize;\n-\n-    LzmaDec_WriteRem(p, limit);\n+    return res;\n   }\n-  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\n-\n-  return 0;\n }\n \n+\n+\n typedef enum\n {\n-  DUMMY_ERROR, /* unexpected end of input stream */\n+  DUMMY_INPUT_EOF, /* need more input data */\n   DUMMY_LIT,\n   DUMMY_MATCH,\n   DUMMY_REP\n } ELzmaDummy;\n \n-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\n+\n+#define IS_DUMMY_END_MARKER_POSSIBLE(dummyRes) ((dummyRes) == DUMMY_MATCH)\n+\n+static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, const Byte **bufOut)\n {\n   UInt32 range = p->range;\n   UInt32 code = p->code;\n-  const Byte *bufLimit = buf + inSize;\n+  const Byte *bufLimit = *bufOut;\n   const CLzmaProb *probs = GET_PROBS;\n   unsigned state = (unsigned)p->state;\n   ELzmaDummy res;\n \n+  for (;;)\n   {\n     const CLzmaProb *prob;\n     UInt32 bound;\n     unsigned ttt;\n-    unsigned posState = CALC_POS_STATE(p->processedPos, (1 << p->prop.pb) - 1);\n+    unsigned posState = CALC_POS_STATE(p->processedPos, ((unsigned)1 << p->prop.pb) - 1);\n \n     prob = probs + IsMatch + COMBINED_PS_STATE;\n     IF_BIT_0_CHECK(prob)\n     {\n       UPDATE_0_CHECK\n \n-      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\n-\n       prob = probs + Literal;\n       if (p->checkDicSize != 0 || p->processedPos != 0)\n         prob += ((UInt32)LZMA_LIT_SIZE *\n-            ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\n-            (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\n+            ((((p->processedPos) & (((unsigned)1 << (p->prop.lp)) - 1)) << p->prop.lc) +\n+            ((unsigned)p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\n \n       if (state < kNumLitStates)\n       {\n@@ -743,8 +797,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS\n           IF_BIT_0_CHECK(prob)\n           {\n             UPDATE_0_CHECK;\n-            NORMALIZE_CHECK;\n-            return DUMMY_REP;\n+            break;\n           }\n           else\n           {\n@@ -820,8 +873,6 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS\n         {\n           unsigned numDirectBits = ((posSlot >> 1) - 1);\n \n-          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\n-\n           if (posSlot < kEndPosModelIndex)\n           {\n             prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);\n@@ -852,12 +903,15 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS\n         }\n       }\n     }\n+    break;\n   }\n   NORMALIZE_CHECK;\n+\n+  *bufOut = buf;\n   return res;\n }\n \n-\n+void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState);\n void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState)\n {\n   p->remainLen = kMatchSpecLenStart + 1;\n@@ -880,16 +934,41 @@ void LzmaDec_Init(CLzmaDec *p)\n }\n \n \n+/*\n+LZMA supports optional end_marker.\n+So the decoder can lookahead for one additional LZMA-Symbol to check end_marker.\n+That additional LZMA-Symbol can require up to LZMA_REQUIRED_INPUT_MAX bytes in input stream.\n+When the decoder reaches dicLimit, it looks (finishMode) parameter:\n+  if (finishMode == LZMA_FINISH_ANY), the decoder doesn't lookahead\n+  if (finishMode != LZMA_FINISH_ANY), the decoder lookahead, if end_marker is possible for current position\n+\n+When the decoder lookahead, and the lookahead symbol is not end_marker, we have two ways:\n+  1) Strict mode (default) : the decoder returns SZ_ERROR_DATA.\n+  2) The relaxed mode (alternative mode) : we could return SZ_OK, and the caller\n+     must check (status) value. The caller can show the error,\n+     if the end of stream is expected, and the (status) is noit\n+     LZMA_STATUS_FINISHED_WITH_MARK or LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK.\n+*/\n+\n+\n+#define RETURN__NOT_FINISHED__FOR_FINISH \\\n+  *status = LZMA_STATUS_NOT_FINISHED; \\\n+  return SZ_ERROR_DATA; // for strict mode\n+  // return SZ_OK; // for relaxed mode\n+\n+\n SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\n     ELzmaFinishMode finishMode, ELzmaStatus *status)\n {\n   SizeT inSize = *srcLen;\n   (*srcLen) = 0;\n-\n   *status = LZMA_STATUS_NOT_SPECIFIED;\n \n   if (p->remainLen > kMatchSpecLenStart)\n   {\n+    if (p->remainLen > kMatchSpecLenStart + 2)\n+      return p->remainLen == kMatchSpecLen_Error_Fail ? SZ_ERROR_FAIL : SZ_ERROR_DATA;\n+\n     for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\n       p->tempBuf[p->tempBufSize++] = *src++;\n     if (p->tempBufSize != 0 && p->tempBuf[0] != 0)\n@@ -904,6 +983,12 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr\n       | ((UInt32)p->tempBuf[2] << 16)\n       | ((UInt32)p->tempBuf[3] << 8)\n       | ((UInt32)p->tempBuf[4]);\n+\n+    if (p->checkDicSize == 0\n+        && p->processedPos == 0\n+        && p->code >= kBadRepCode)\n+      return SZ_ERROR_DATA;\n+\n     p->range = 0xFFFFFFFF;\n     p->tempBufSize = 0;\n \n@@ -921,10 +1006,21 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr\n     p->remainLen = 0;\n   }\n \n-  LzmaDec_WriteRem(p, dicLimit);\n-\n-  while (p->remainLen != kMatchSpecLenStart)\n+  for (;;)\n   {\n+    if (p->remainLen == kMatchSpecLenStart)\n+    {\n+      if (p->code != 0)\n+        return SZ_ERROR_DATA;\n+      *status = LZMA_STATUS_FINISHED_WITH_MARK;\n+      return SZ_OK;\n+    }\n+\n+    LzmaDec_WriteRem(p, dicLimit);\n+\n+    {\n+      // (p->remainLen == 0 || p->dicPos == dicLimit)\n+\n       int checkEndMarkNow = 0;\n \n       if (p->dicPos >= dicLimit)\n@@ -941,92 +1037,174 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr\n         }\n         if (p->remainLen != 0)\n         {\n-          *status = LZMA_STATUS_NOT_FINISHED;\n-          return SZ_ERROR_DATA;\n+          RETURN__NOT_FINISHED__FOR_FINISH;\n         }\n         checkEndMarkNow = 1;\n       }\n \n+      // (p->remainLen == 0)\n+\n       if (p->tempBufSize == 0)\n       {\n-        SizeT processed;\n         const Byte *bufLimit;\n+        int dummyProcessed = -1;\n+\n         if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\n         {\n-          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\n-          if (dummyRes == DUMMY_ERROR)\n+          const Byte *bufOut = src + inSize;\n+\n+          ELzmaDummy dummyRes = LzmaDec_TryDummy(p, src, &bufOut);\n+\n+          if (dummyRes == DUMMY_INPUT_EOF)\n           {\n-            memcpy(p->tempBuf, src, inSize);\n-            p->tempBufSize = (unsigned)inSize;\n+            size_t i;\n+            if (inSize >= LZMA_REQUIRED_INPUT_MAX)\n+              break;\n             (*srcLen) += inSize;\n+            p->tempBufSize = (unsigned)inSize;\n+            for (i = 0; i < inSize; i++)\n+              p->tempBuf[i] = src[i];\n             *status = LZMA_STATUS_NEEDS_MORE_INPUT;\n             return SZ_OK;\n           }\n-          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\n+\n+          dummyProcessed = (int)(bufOut - src);\n+          if ((unsigned)dummyProcessed > LZMA_REQUIRED_INPUT_MAX)\n+            break;\n+\n+          if (checkEndMarkNow && !IS_DUMMY_END_MARKER_POSSIBLE(dummyRes))\n           {\n-            *status = LZMA_STATUS_NOT_FINISHED;\n-            return SZ_ERROR_DATA;\n+            unsigned i;\n+            (*srcLen) += (unsigned)dummyProcessed;\n+            p->tempBufSize = (unsigned)dummyProcessed;\n+            for (i = 0; i < (unsigned)dummyProcessed; i++)\n+              p->tempBuf[i] = src[i];\n+            // p->remainLen = kMatchSpecLen_Error_Data;\n+            RETURN__NOT_FINISHED__FOR_FINISH;\n           }\n+\n           bufLimit = src;\n+          // we will decode only one iteration\n         }\n         else\n           bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\n+\n         p->buf = src;\n-        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\n-          return SZ_ERROR_DATA;\n-        processed = (SizeT)(p->buf - src);\n-        (*srcLen) += processed;\n-        src += processed;\n-        inSize -= processed;\n+\n+        {\n+          int res = LzmaDec_DecodeReal2(p, dicLimit, bufLimit);\n+\n+          SizeT processed = (SizeT)(p->buf - src);\n+\n+          if (dummyProcessed < 0)\n+          {\n+            if (processed > inSize)\n+              break;\n+          }\n+          else if ((unsigned)dummyProcessed != processed)\n+            break;\n+\n+          src += processed;\n+          inSize -= processed;\n+          (*srcLen) += processed;\n+\n+          if (res != SZ_OK)\n+          {\n+            p->remainLen = kMatchSpecLen_Error_Data;\n+            return SZ_ERROR_DATA;\n+          }\n+        }\n+        continue;\n       }\n-      else\n+\n       {\n-        unsigned rem = p->tempBufSize, lookAhead = 0;\n-        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\n-          p->tempBuf[rem++] = src[lookAhead++];\n-        p->tempBufSize = rem;\n+        // we have some data in (p->tempBuf)\n+        // in strict mode: tempBufSize is not enough for one Symbol decoding.\n+        // in relaxed mode: tempBufSize not larger than required for one Symbol decoding.\n+\n+        unsigned rem = p->tempBufSize;\n+        unsigned ahead = 0;\n+        int dummyProcessed = -1;\n+\n+        while (rem < LZMA_REQUIRED_INPUT_MAX && ahead < inSize)\n+          p->tempBuf[rem++] = src[ahead++];\n+\n+        // ahead - the size of new data copied from (src) to (p->tempBuf)\n+        // rem   - the size of temp buffer including new data from (src)\n+\n         if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\n         {\n-          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, (SizeT)rem);\n-          if (dummyRes == DUMMY_ERROR)\n+          const Byte *bufOut = p->tempBuf + rem;\n+\n+          ELzmaDummy dummyRes = LzmaDec_TryDummy(p, p->tempBuf, &bufOut);\n+\n+          if (dummyRes == DUMMY_INPUT_EOF)\n           {\n-            (*srcLen) += (SizeT)lookAhead;\n+            if (rem >= LZMA_REQUIRED_INPUT_MAX)\n+              break;\n+            p->tempBufSize = rem;\n+            (*srcLen) += (SizeT)ahead;\n             *status = LZMA_STATUS_NEEDS_MORE_INPUT;\n             return SZ_OK;\n           }\n-          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\n+\n+          dummyProcessed = (int)(bufOut - p->tempBuf);\n+\n+          if ((unsigned)dummyProcessed < p->tempBufSize)\n+            break;\n+\n+          if (checkEndMarkNow && !IS_DUMMY_END_MARKER_POSSIBLE(dummyRes))\n           {\n-            *status = LZMA_STATUS_NOT_FINISHED;\n-            return SZ_ERROR_DATA;\n+            (*srcLen) += (unsigned)dummyProcessed - p->tempBufSize;\n+            p->tempBufSize = (unsigned)dummyProcessed;\n+            // p->remainLen = kMatchSpecLen_Error_Data;\n+            RETURN__NOT_FINISHED__FOR_FINISH;\n           }\n         }\n+\n         p->buf = p->tempBuf;\n-        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\n-          return SZ_ERROR_DATA;\n \n         {\n-          unsigned kkk = (unsigned)(p->buf - p->tempBuf);\n-          if (rem < kkk)\n-            return SZ_ERROR_FAIL; /* some internal error */\n-          rem -= kkk;\n-          if (lookAhead < rem)\n-            return SZ_ERROR_FAIL; /* some internal error */\n-          lookAhead -= rem;\n+          // we decode one symbol from (p->tempBuf) here, so the (bufLimit) is equal to (p->buf)\n+          int res = LzmaDec_DecodeReal2(p, dicLimit, p->buf);\n+\n+          SizeT processed = (SizeT)(p->buf - p->tempBuf);\n+          rem = p->tempBufSize;\n+\n+          if (dummyProcessed < 0)\n+          {\n+            if (processed > LZMA_REQUIRED_INPUT_MAX)\n+              break;\n+            if (processed < rem)\n+              break;\n+          }\n+          else if ((unsigned)dummyProcessed != processed)\n+            break;\n+\n+          processed -= rem;\n+\n+          src += processed;\n+          inSize -= processed;\n+          (*srcLen) += processed;\n+          p->tempBufSize = 0;\n+\n+          if (res != SZ_OK)\n+          {\n+            p->remainLen = kMatchSpecLen_Error_Data;\n+            return SZ_ERROR_DATA;\n+          }\n         }\n-        (*srcLen) += (SizeT)lookAhead;\n-        src += lookAhead;\n-        inSize -= (SizeT)lookAhead;\n-        p->tempBufSize = 0;\n       }\n+    }\n   }\n \n-  if (p->code != 0)\n-    return SZ_ERROR_DATA;\n-  *status = LZMA_STATUS_FINISHED_WITH_MARK;\n-  return SZ_OK;\n+  /*  Some unexpected error: internal error of code, memory corruption or hardware failure */\n+  p->remainLen = kMatchSpecLen_Error_Fail;\n+  return SZ_ERROR_FAIL;\n }\n \n \n+\n SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\n {\n   SizeT outSize = *destLen;\ndiff --git a/lib/lzma/LzmaDec.h b/lib/lzma/LzmaDec.h\nindex f3702f5ce608..3ab4920037c1 100644\n--- a/lib/lzma/LzmaDec.h\n+++ b/lib/lzma/LzmaDec.h\n@@ -1,5 +1,5 @@\n /* LzmaDec.h -- LZMA Decoder\n-2018-04-21 : Igor Pavlov : Public domain */\n+2020-03-19 : Igor Pavlov : Public domain */\n \n #ifndef __LZMA_DEC_H\n #define __LZMA_DEC_H\n@@ -181,6 +181,7 @@ Returns:\n       LZMA_STATUS_NEEDS_MORE_INPUT\n       LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\n   SZ_ERROR_DATA - Data error\n+  SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure\n */\n \n SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\n@@ -223,6 +224,7 @@ Returns:\n   SZ_ERROR_MEM  - Memory allocation error\n   SZ_ERROR_UNSUPPORTED - Unsupported properties\n   SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\n+  SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure\n */\n \n SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\n","prefixes":["RFC","6/9"]}