From nobody Tue May 7 00:24:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+67213+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67213+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1604976104; cv=none; d=zohomail.com; s=zohoarc; b=jZer8PyzebyEGcXMysaKtdKrKeY0SqQ+abzvBniKGjN2cwHywhh+By6hriqSZT5YI9XobwtSm+3vsNzqc6S/ZrUQ8B7Ec+bRWzxbKAqKSGT6o69hRkK26/gwquI4mLVae8ajNO/vS78aiKcUH/M+Pi2obkscTngy/zbSOkzfyy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604976104; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=KWwJmwg2PDglD50KPBuG9Oa79Yul5Ws9NPFYr7x6rB0=; b=Ek8Qb78lP2/wGkJPY81I5tlnI6LGDoaGom0waThEhL3/qoEOloriekQ9ivFnRRi+1WbWixthibhaI0MGv4qXERTM5dNYs8QD1anBtwBKIGE8QCZGLb6rzM2Z9Cg5fWXxo+WrUwlTxCEt7mESBATGiMJVCNXLlETlBBWPrDgG3VM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67213+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604976104596780.8948930513417; Mon, 9 Nov 2020 18:41:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jQKwYY1788612xwbftSCd3x4; Mon, 09 Nov 2020 18:41:44 -0800 X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web12.22365.1604976095792352318 for ; Mon, 09 Nov 2020 18:41:37 -0800 X-Received: from localhost.localdomain ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Tue, 10 Nov 2020 10:41:32 +0800 X-WM-Sender: fengyunhua@byosoft.com.cn From: "fengyunhua" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao , Yuwei Chen Subject: [edk2-devel] [PATCH] BaseTools: Fix BrotliCompress tool issue Date: Tue, 10 Nov 2020 10:41:08 +0800 Message-Id: <20201110024108.2445-1-fengyunhua@byosoft.com.cn> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,fengyunhua@byosoft.com.cn X-Gm-Message-State: AGfhXaqsmNnej3df1T3VhoDKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604976104; bh=HIyegyg5EzyNgZlZiXOsT9zHwYJNOL258WqBSsJugSQ=; h=Cc:Date:From:Reply-To:Subject:To; b=XgO6arC/XDJh5G2CXJ49bcBjOrHcsXRPva20F0koqoa2Lr18MZ/RagkZngErZ99MLsI PL4wa6Jms1sZZ9zUui4AFf9MOjzoClgGWzQgT7HIWXH+JWuIgL7PbN7gfgVFAyopamM7p 8oqj29skRXuJSOq3glHoyS6k7DZN5E0DzBA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2946 This is the regression issue in BaseTools BrotliCompress after Brotli is changed to submodule. BrotliCompress should store the source size and scratch buffer size into the header of the compressed binary data. But now, BrotliCompress doesn't store them. So, BrotliDecompress can't work. To fix this issue, BrotliCompress tool main() function should be provided. It needs to support the options of -e, -d, -o file, -g gap, -q level. Cc: Bob Feng Cc: Liming Gao Cc: Yuwei Chen Signed-off-by: Yunhua Feng Reviewed-by: Liming Gao Tested-by: Liming Gao --- .../WindowsLike/BrotliCompress.bat | 55 -- .../Source/C/BrotliCompress/BrotliCompress.c | 572 ++++++++++++++++++ BaseTools/Source/C/BrotliCompress/GNUmakefile | 4 +- BaseTools/Source/C/BrotliCompress/Makefile | 4 +- 4 files changed, 576 insertions(+), 59 deletions(-) delete mode 100644 BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat create mode 100644 BaseTools/Source/C/BrotliCompress/BrotliCompress.c diff --git a/BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat b/BaseToo= ls/BinWrappers/WindowsLike/BrotliCompress.bat deleted file mode 100644 index 788c99a130..0000000000 --- a/BaseTools/BinWrappers/WindowsLike/BrotliCompress.bat +++ /dev/null @@ -1,55 +0,0 @@ -@REM @file -@REM This script will exec Brotli tool with -e/-d options. -@REM -@REM Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
-@REM SPDX-License-Identifier: BSD-2-Clause-Patent -@REM - -@echo off -@setlocal - -set QLT=3D-q 9 -w 22 -set ARGS=3D - -:Begin -if "%1"=3D=3D"" goto End - -if "%1"=3D=3D"-d" ( - set ARGS=3D%ARGS% %1 - shift - goto Begin -) - -if "%1"=3D=3D"-e" ( - shift - goto Begin -) - -if "%1"=3D=3D"-g" ( - set ARGS=3D%ARGS% %1 %2 - shift - shift - goto Begin -) - -if "%1"=3D=3D"-o" ( - set ARGS=3D%ARGS% %1 %2 - shift - shift - goto Begin -) - -if "%1"=3D=3D"-q" ( - set QLT=3D%1 %2 - shift - shift - goto Begin -) - -set ARGS=3D%ARGS% %1 -shift -goto Begin - -:End -Brotli %QLT% %ARGS% -@echo on diff --git a/BaseTools/Source/C/BrotliCompress/BrotliCompress.c b/BaseTools= /Source/C/BrotliCompress/BrotliCompress.c new file mode 100644 index 0000000000..5a1400fda3 --- /dev/null +++ b/BaseTools/Source/C/BrotliCompress/BrotliCompress.c @@ -0,0 +1,572 @@ +/** @file + BrotliCompress Compress/Decompress tool (BrotliCompress) + + Copyright (c) 2020, ByoSoft Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +/* Command line interface for Brotli library. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "./brotli/c/common/constants.h" +#include "./brotli/c/common/version.h" +#include +#include + +#if !defined(_WIN32) +#include +#include +#else +#include +#include +#include + +#if !defined(__MINGW32__) +#define STDIN_FILENO _fileno(stdin) +#define STDOUT_FILENO _fileno(stdout) +#define S_IRUSR S_IREAD +#define S_IWUSR S_IWRITE +#endif + +#define fopen ms_fopen +#define open ms_open + +#if defined(_MSC_VER) && (_MSC_VER >=3D 1400) +#define fseek _fseeki64 +#define ftell _ftelli64 +#endif + +static FILE* ms_fopen(const char* FileName, const char* Mode) { + FILE* Result; + Result =3D NULL; + fopen_s(&Result, FileName, Mode); + return Result; +} + +static int ms_open(const char* FileName, int Oflag, int Pmode) { + int Result; + Result =3D -1; + _sopen_s(&Result, FileName, Oflag | O_BINARY, _SH_DENYNO, Pmode); + return Result; +} +#endif /* WIN32 */ + + +#ifndef _MAX_PATH +#define _MAX_PATH 500 +#endif + +#define DEFAULT_LGWIN 22 +#define DECODE_HEADER_SIZE 0x10 +#define GAP_MEM_BLOCK 0x1000 +size_t ScratchBufferSize =3D 0; +static const size_t kFileBufferSize =3D 1 << 19; + +static void Version(void) { + int Major; + int Minor; + int Patch; + Major =3D BROTLI_VERSION >> 24; + Minor =3D (BROTLI_VERSION >> 12) & 0xFFF; + Patch =3D BROTLI_VERSION & 0xFFF; + printf("BrotliCompress %d.%d.%d\n", Major, Minor, Patch); +} + +static void Usage() { + printf("Usage: %s [OPTION]... [FILE]...\n", __FILE__); + printf( +"Options:\n" +" -e, --compress compress\n" +" -d, --decompress decompress\n" +" -h, --help display this help and exit\n"); + printf( +" -o FILE, --output=3DFILE output file (only if 1 input file)\n"); + printf( +" -g NUM, --gap=3DNUM scratch memory gap level (1-16)\n"); + printf( +" -q NUM, --quality=3DNUM compression level (%d-%d)\n", + BROTLI_MIN_QUALITY, BROTLI_MAX_QUALITY); + printf( +" -v, --version display version and exit\n"); +} + +static int64_t FileSize(const char* Path) { + FILE *FileHandle; + int64_t RetVal; + FileHandle =3D fopen(Path, "rb"); + + if (FileHandle =3D=3D NULL) { + printf ("Failed to open file [%s]\n", Path); + return -1; + } + if (fseek(FileHandle, 0L, SEEK_END) !=3D 0) { + printf ("Failed to seek file [%s]\n", Path); + fclose(FileHandle); + return -1; + } + RetVal =3D ftell(FileHandle); + if (fclose(FileHandle) !=3D 0) { + printf ("Failed to close file [%s]\n", Path); + return -1; + } + return RetVal; +} + +static BROTLI_BOOL HasMoreInput(FILE *FileHandle) { + return feof(FileHandle) ? BROTLI_FALSE : BROTLI_TRUE; +} + +int OpenFiles(char *InputFile, FILE **InHandle, char *OutputFile, FILE **O= utHandle) { + *InHandle =3D NULL; + *OutHandle =3D NULL; + *InHandle =3D fopen(InputFile, "rb"); + if (*InHandle =3D=3D NULL) { + printf("Failed to open input file [%s]\n", InputFile); + return BROTLI_FALSE; + } + + *OutHandle =3D fopen(OutputFile, "wb+"); + if (*OutHandle =3D=3D NULL) { + printf("Failed to open output file [%s]\n", OutputFile); + fclose(*InHandle); + return BROTLI_FALSE; + } + return BROTLI_TRUE; +} + +int CompressFile(char *InputFile, uint8_t *InputBuffer, char *OutputFile, = uint8_t *OutputBuffer, int Quality, int Gap) { + int64_t InputFileSize; + FILE *InputFileHandle; + FILE *OutputFileHandle; + BrotliEncoderState *EncodeState; + uint32_t LgWin; + BROTLI_BOOL IsEof; + size_t AvailableIn; + const uint8_t *NextIn; + size_t AvailableOut; + uint8_t *NextOut; + uint8_t *Input; + uint8_t *Output; + size_t OutSize; + uint32_t SizeHint; + BROTLI_BOOL IsOk; + AvailableIn =3D 0; + IsEof =3D BROTLI_FALSE; + Input =3D InputBuffer; + Output =3D OutputBuffer; + IsOk =3D BROTLI_TRUE; + LgWin =3D DEFAULT_LGWIN; + + InputFileSize =3D FileSize(InputFile); + + IsOk =3D OpenFiles(InputFile, &InputFileHandle, OutputFile, &OutputFileH= andle); + if (!IsOk) { + return IsOk; + } + + fseek (OutputFileHandle, DECODE_HEADER_SIZE, SEEK_SET); + + EncodeState =3D BrotliEncoderCreateInstance(NULL, NULL, NULL); + if (!EncodeState) { + printf("Out of memory\n"); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + BrotliEncoderSetParameter(EncodeState, BROTLI_PARAM_QUALITY, (uint32_t)Q= uality); + + if (InputFileSize >=3D 0) { + LgWin =3D BROTLI_MIN_WINDOW_BITS; + while (BROTLI_MAX_BACKWARD_LIMIT(LgWin) < InputFileSize) { + LgWin++; + if (LgWin =3D=3D BROTLI_MAX_WINDOW_BITS) { + break; + } + } + } + BrotliEncoderSetParameter(EncodeState, BROTLI_PARAM_LGWIN, LgWin); + if (InputFileSize > 0) { + SizeHint =3D InputFileSize < (1 << 30)? (uint32_t)InputFileSize : (1u = << 30); + BrotliEncoderSetParameter(EncodeState, BROTLI_PARAM_SIZE_HINT, SizeHin= t); + } + + AvailableIn =3D 0; + NextIn =3D NULL; + AvailableOut =3D kFileBufferSize; + NextOut =3D Output; + for (;;) { + if (AvailableIn =3D=3D 0 && !IsEof) { + AvailableIn =3D fread(Input, 1, kFileBufferSize, InputFileHandle); + NextIn =3D Input; + if (ferror(InputFileHandle)) { + printf("Failed to read input [%s]\n", InputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + IsEof =3D !HasMoreInput(InputFileHandle); + } + + if (!BrotliEncoderCompressStream(EncodeState, + IsEof ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS, + &AvailableIn, &NextIn, &AvailableOut, &NextOut, NULL)) { + printf("Failed to compress data [%s]\n", InputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + if (AvailableOut =3D=3D 0) { + OutSize =3D (size_t)(NextOut - Output); + if (OutSize > 0) { + fwrite(Output, 1, OutSize, OutputFileHandle); + if (ferror(OutputFileHandle)) { + printf("Failed to write output [%s]\n", OutputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + } + AvailableOut =3D kFileBufferSize; + NextOut =3D Output; + } + if (BrotliEncoderIsFinished(EncodeState)) { + OutSize =3D (size_t)(NextOut - Output); + if (OutSize > 0) { + fwrite(Output, 1, OutSize, OutputFileHandle); + if (ferror(OutputFileHandle)) { + printf("Failed to write output [%s]\n", OutputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + AvailableOut =3D 0; + } + } + if (IsEof) { + break; + } + } + +Finish: + if (EncodeState) { + BrotliEncoderDestroyInstance(EncodeState); + } + if (InputFileHandle) { + fclose(InputFileHandle); + } + if (OutputFileHandle) { + fclose(OutputFileHandle); + } + return IsOk; +} + +/* Default BrotliAllocFunc */ +void* BrotliAllocFunc(void* Opaque, size_t Size) { + *(size_t *)Opaque =3D *(size_t *) Opaque + Size; + return malloc(Size); +} + +/* Default BrotliFreeFunc */ +void BrotliFreeFunc(void* Opaque, void* Address) { + free(Address); +} + +int DecompressFile(char *InputFile, uint8_t *InputBuffer, char *OutputFile= , uint8_t *OutputBuffer, int Quality, int Gap) { + FILE *InputFileHandle; + FILE *OutputFileHandle; + BrotliDecoderState *DecoderState; + BrotliDecoderResult Result; + size_t AvailableIn; + const uint8_t *NextIn; + size_t AvailableOut; + uint8_t *NextOut; + uint8_t *Input; + uint8_t *Output; + size_t OutSize; + BROTLI_BOOL IsOk; + AvailableIn =3D 0; + Input =3D InputBuffer; + Output =3D OutputBuffer; + IsOk =3D BROTLI_TRUE; + + IsOk =3D OpenFiles(InputFile, &InputFileHandle, OutputFile, &OutputFileH= andle); + if (!IsOk) { + return IsOk; + } + fseek(InputFileHandle, DECODE_HEADER_SIZE, SEEK_SET); + + DecoderState =3D BrotliDecoderCreateInstance(BrotliAllocFunc, BrotliFree= Func, &ScratchBufferSize); + if (!DecoderState) { + printf("Out of memory\n"); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + /* This allows decoding "large-window" streams. Though it creates + fragmentation (new builds decode streams that old builds don't), + it is better from used experience perspective. */ + BrotliDecoderSetParameter(DecoderState, BROTLI_DECODER_PARAM_LARGE_WINDO= W, 1u); + + AvailableIn =3D 0; + NextIn =3D NULL; + AvailableOut =3D kFileBufferSize; + NextOut =3D Output; + Result =3D BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; + for (;;) { + if (Result =3D=3D BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) { + if (!HasMoreInput(InputFileHandle)) { + printf("Corrupt input [%s]\n", InputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + AvailableIn =3D fread(Input, 1, kFileBufferSize, InputFileHandle); + NextIn =3D Input; + if (ferror(InputFileHandle)) { + printf("Failed to read input [%s]\n", InputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + } else if (Result =3D=3D BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) { + OutSize =3D (size_t) (NextOut - Output); + if (OutSize > 0) { + fwrite(Output, 1, OutSize, OutputFileHandle); + if (ferror(OutputFileHandle)) { + printf("Failed to write output [%s]\n", OutputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + } + AvailableOut =3D kFileBufferSize; + NextOut =3D Output; + } else if (Result =3D=3D BROTLI_DECODER_RESULT_SUCCESS) { + OutSize =3D (size_t) (NextOut - Output); + if (OutSize > 0) { + fwrite(Output, 1, OutSize, OutputFileHandle); + if (ferror(OutputFileHandle)) { + printf("Failed to write output [%s]\n", OutputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + } + AvailableOut =3D 0; + if (AvailableIn !=3D 0 || HasMoreInput(InputFileHandle)) { + printf("Corrupt input [%s]\n", InputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + } else { + printf("Corrupt input [%s]\n", InputFile); + IsOk =3D BROTLI_FALSE; + goto Finish; + } + if (!HasMoreInput(InputFileHandle) && Result =3D=3D BROTLI_DECODER_RES= ULT_SUCCESS ) { + break; + } + Result =3D BrotliDecoderDecompressStream(DecoderState, &AvailableIn, &= NextIn, &AvailableOut, &NextOut, 0); + } +Finish: + if (DecoderState) { + BrotliDecoderDestroyInstance(DecoderState); + } + if (InputFileHandle) { + fclose(InputFileHandle); + } + if (OutputFileHandle) { + fclose(OutputFileHandle); + } + return IsOk; +} + +int main(int argc, char** argv) { + BROTLI_BOOL CompressBool; + BROTLI_BOOL DecompressBool; + char *OutputFile; + char *InputFile; + char OutputTmpFile[_MAX_PATH]; + FILE *OutputHandle; + int Quality; + int Gap; + int OutputFileLength; + int InputFileLength; + int Ret; + size_t InputFileSize; + uint8_t *Buffer; + uint8_t *InputBuffer; + uint8_t *OutputBuffer; + int64_t Size; + + InputFile =3D NULL; + OutputFile =3D NULL; + CompressBool =3D BROTLI_FALSE; + DecompressBool =3D BROTLI_FALSE; + // + //Set default Quality and Gap + // + Quality =3D 9; + Gap =3D 1; + InputFileSize =3D 0; + Ret =3D 0; + + if (argc < 2) { + Usage(); + return 1; + } + if (strcmp(argv[1], "-h") =3D=3D 0 || strcmp (argv[1], "--help") =3D=3D = 0 ) { + Usage(); + return 0; + } + if (strcmp(argv[1], "-v") =3D=3D 0 || strcmp (argv[1], "--version") =3D= =3D 0 ) { + Version(); + return 0; + } + while (argc > 1) { + if (strcmp(argv[1], "-e") =3D=3D 0 || strcmp(argv[1], "--compress") = =3D=3D 0 ) { + CompressBool =3D BROTLI_TRUE; + if (DecompressBool) { + printf("Can't use -e/--compress with -d/--decompess on the same ti= me\n"); + return 1; + } + argc--; + argv++; + continue; + } + if (strcmp(argv[1], "-d") =3D=3D 0 || strcmp(argv[1], "--decompress") = =3D=3D 0 ) { + DecompressBool =3D BROTLI_TRUE; + if (CompressBool) { + printf("Can't use -e/--compress with -d/--decompess on the same ti= me\n"); + return 1; + } + argc--; + argv++; + continue; + } + if (strcmp(argv[1], "-o") =3D=3D 0 || strncmp(argv[1], "--output", 8) = =3D=3D 0) { + if (strcmp(argv[1], "-o") =3D=3D 0) { + OutputFileLength =3D strlen(argv[2]); + if (OutputFileLength > _MAX_PATH) { + printf ("The file path %s is too long\n", argv[2]); + return 1; + } + OutputFile =3D argv[2]; + if (OutputFile =3D=3D NULL) { + fprintf(stderr, "Input file can't be null\n"); + return 1; + } + argc--; + argv++; + } else { + OutputFileLength =3D strlen(argv[1] - 9); + OutputFile =3D (char *)argv[1] + 9; + } + argc--; + argv++; + continue; + } + if (strcmp(argv[1], "-q") =3D=3D 0 || strncmp(argv[1], "--quality", 9)= =3D=3D 0) { + if (strcmp(argv[1], "-q") =3D=3D 0) { + Quality =3D strtol(argv[2], NULL, 16); + argc--; + argv++; + } else { + Quality =3D strtol((char *)argv[1] + 10, NULL, 16); + } + argc--; + argv++; + continue; + } + if (strcmp(argv[1], "-g") =3D=3D 0 || strncmp(argv[1], "--gap", 5) =3D= =3D 0) { + if (strcmp(argv[1], "-g") =3D=3D 0) { + Gap =3D strtol(argv[2], NULL, 16); + argc--; + argv++; + } else { + Gap =3D strtol((char *)argv[1] + 6, NULL, 16); + } + argc--; + argv++; + continue; + } + if (argc > 1) { + InputFileLength =3D strlen(argv[1]); + if (InputFileLength > _MAX_PATH - 1) { + printf ("The file path %s is too long\n", argv[2]); + return 1; + } + InputFile =3D argv[1]; + if (InputFile =3D=3D NULL) { + printf("Input file can't be null\n"); + return 1; + } + argc--; + argv++; + } + } + + Buffer =3D (uint8_t*)malloc(kFileBufferSize * 2); + if (!Buffer) { + printf("Out of memory\n"); + goto Finish; + } + memset(Buffer, 0, kFileBufferSize*2); + InputBuffer =3D Buffer; + OutputBuffer =3D Buffer + kFileBufferSize; + if (CompressBool) { + // + // Compress file + // + Ret =3D CompressFile(InputFile, InputBuffer, OutputFile, OutputBuffer,= Quality, Gap); + if (!Ret) { + printf ("Failed to compress file [%s]\n", InputFile); + goto Finish; + } + // + // Decompress file for get Outputfile size + // + strcpy (OutputTmpFile, OutputFile); + if (strlen(InputFile) + strlen(".tmp") < _MAX_PATH) { + strcat(OutputTmpFile, ".tmp"); + } else { + printf ("Output file path is too long[%s]\n", OutputFile); + Ret =3D BROTLI_FALSE; + goto Finish; + } + memset(Buffer, 0, kFileBufferSize*2); + Ret =3D DecompressFile(OutputFile, InputBuffer, OutputTmpFile, OutputB= uffer, Quality, Gap); + if (!Ret) { + printf ("Failed to decompress file [%s]\n", OutputFile); + goto Finish; + } + remove (OutputTmpFile); + + // + // fill decoder header + // + InputFileSize =3D FileSize(InputFile); + Size =3D (int64_t)InputFileSize; + OutputHandle =3D fopen(OutputFile, "rb+"); /* open output_path file an= d add in head info */ + fwrite(&Size, 1, sizeof(int64_t), OutputHandle); + ScratchBufferSize +=3D Gap * GAP_MEM_BLOCK; /* there is a memory gap b= etween IA32 and X64 environment*/ + ScratchBufferSize +=3D kFileBufferSize * 2; + Size =3D (int64_t) ScratchBufferSize; + fwrite(&Size, 1, sizeof(int64_t), OutputHandle); + if (fclose(OutputHandle) !=3D 0) { + printf("Failed to close output file [%s]\n", OutputFile); + Ret =3D BROTLI_FALSE; + goto Finish; + } + } else { + Ret =3D DecompressFile(InputFile, InputBuffer, OutputFile, OutputBuffe= r, Quality, Gap); + if (!Ret) { + printf ("Failed to decompress file [%s]\n", InputFile); + goto Finish; + } + } + Finish: + if (Buffer !=3D NULL) { + free (Buffer); + } + return !Ret; +} diff --git a/BaseTools/Source/C/BrotliCompress/GNUmakefile b/BaseTools/Sour= ce/C/BrotliCompress/GNUmakefile index 9544837263..b150e5dd2b 100644 --- a/BaseTools/Source/C/BrotliCompress/GNUmakefile +++ b/BaseTools/Source/C/BrotliCompress/GNUmakefile @@ -6,10 +6,10 @@ # MAKEROOT ?=3D .. =20 -APPNAME =3D Brotli +APPNAME =3D BrotliCompress =20 OBJECTS =3D \ - brotli/c/tools/brotli.o \ + BrotliCompress.o \ brotli/c/common/dictionary.o \ brotli/c/common/transform.o \ brotli/c/dec/bit_reader.o \ diff --git a/BaseTools/Source/C/BrotliCompress/Makefile b/BaseTools/Source/= C/BrotliCompress/Makefile index b805ff1e58..038d1ec242 100644 --- a/BaseTools/Source/C/BrotliCompress/Makefile +++ b/BaseTools/Source/C/BrotliCompress/Makefile @@ -9,7 +9,7 @@ INC =3D -I .\brotli\c\include $(INC) CFLAGS =3D $(CFLAGS) /W2 =20 -APPNAME =3D Brotli +APPNAME =3D BrotliCompress =20 #LIBS =3D $(LIB_PATH)\Common.lib =20 @@ -40,7 +40,7 @@ ENC_OBJ =3D \ brotli\c\enc\utf8_util.obj =20 OBJECTS =3D \ - brotli\c\tools\brotli.obj \ + BrotliCompress.obj \ $(COMMON_OBJ) \ $(DEC_OBJ) \ $(ENC_OBJ) --=20 2.27.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#67213): https://edk2.groups.io/g/devel/message/67213 Mute This Topic: https://groups.io/mt/78152272/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-