Skip to content

Commit

Permalink
[cmp] update Bled to latest
Browse files Browse the repository at this point in the history
* This adds ZIP64 support, which is required to extract zip archives that are larger than 4GB.
* Closes #2264
* Also fix a MinGW warning in pki.c and improve the UEFI revocation messages.
  • Loading branch information
pbatard committed Jun 28, 2023
1 parent 52a5551 commit f233191
Show file tree
Hide file tree
Showing 11 changed files with 550 additions and 241 deletions.
4 changes: 2 additions & 2 deletions res/loc/rufus.loc
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ t MSG_337 "An additional file ('diskcopy.dll') must be downloaded from Microsoft
"- Select 'No' to cancel the operation\n\n"
"Note: The file will be downloaded in the application's directory and will be reused automatically if present."
t MSG_338 "Revoked UEFI bootloader detected"
t MSG_339 "Rufus detected that the ISO you have selected contains a UEFI bootloader that has been revoked and that will produce %s, on a fully up to date UEFI system with Secure Boot enabled.\n\n"
"- If you obtained this ISO image from a non reputable source, you should consider the possibility that it may contain UEFI malware and avoid booting from it.\n"
t MSG_339 "Rufus detected that the ISO you have selected contains a UEFI bootloader that has been revoked and that will produce %s, when Secure Boot is enabled on a fully up to date UEFI system.\n\n"
"- If you obtained this ISO image from a non reputable source, you should consider the possibility that it might contain UEFI malware and avoid booting from it.\n"
"- If you obtained it from a trusted source, you should try to locate a more up to date version, that will not produce this warning."
t MSG_340 "a \"Security Violation\" screen"
t MSG_341 "a Windows Recovery Screen (BSOD) with '%s'"
Expand Down
2 changes: 2 additions & 0 deletions src/bled/bb_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ static inline int transformer_switch_file(transformer_state_t* xstate)
xstate->dst_fd = -1;
}
_snprintf_s(dst, sizeof(dst), _TRUNCATE, "%s/%s", xstate->dst_dir, xstate->dst_name);
free(xstate->dst_name);
xstate->dst_name = NULL;
for (i = 0; i < strlen(dst); i++) {
if (dst[i] == '/')
dst[i] = '\\';
Expand Down
33 changes: 15 additions & 18 deletions src/bled/bled.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Bled (Base Library for Easy Decompression)
*
* Copyright © 2014-2020 Pete Batard <pete@akeo.ie>
* Copyright © 2014-2023 Pete Batard <pete@akeo.ie>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
Expand Down Expand Up @@ -54,7 +54,7 @@ unpacker_t unpacker[BLED_COMPRESSION_MAX] = {
int64_t bled_uncompress(const char* src, const char* dst, int type)
{
transformer_state_t xstate;
int64_t ret;
int64_t ret = -1;

if (!bled_initialized) {
bb_error_msg("The library has not been initialized");
Expand Down Expand Up @@ -85,17 +85,16 @@ int64_t bled_uncompress(const char* src, const char* dst, int type)

if (setjmp(bb_error_jmp))
goto err;

ret = unpacker[type](&xstate);
_close(xstate.src_fd);
_close(xstate.dst_fd);
return ret;

err:
free(xstate.dst_name);
if (xstate.src_fd > 0)
_close(xstate.src_fd);
if (xstate.dst_fd > 0)
_close(xstate.dst_fd);
return -1;
return ret;
}

/* Uncompress using Windows handles */
Expand Down Expand Up @@ -132,14 +131,15 @@ int64_t bled_uncompress_with_handles(HANDLE hSrc, HANDLE hDst, int type)

if (setjmp(bb_error_jmp))
return -1;

return unpacker[type](&xstate);
}

/* Uncompress file 'src', compressed using 'type', to buffer 'buf' of size 'size' */
int64_t bled_uncompress_to_buffer(const char* src, char* buf, size_t size, int type)
{
transformer_state_t xstate;
int64_t ret;
int64_t ret = -1;

if (!bled_initialized) {
bb_error_msg("The library has not been initialized");
Expand Down Expand Up @@ -177,22 +177,21 @@ int64_t bled_uncompress_to_buffer(const char* src, char* buf, size_t size, int t

if (setjmp(bb_error_jmp))
goto err;

ret = unpacker[type](&xstate);
if (src[0] != 0)
_close(xstate.src_fd);
return ret;

err:
if (xstate.src_fd > 0)
free(xstate.dst_name);
if ((src[0] != 0) && (xstate.src_fd > 0))
_close(xstate.src_fd);
return -1;
return ret;
}

/* Uncompress all files from archive 'src', compressed using 'type', to destination dir 'dir' */
int64_t bled_uncompress_to_dir(const char* src, const char* dir, int type)
{
transformer_state_t xstate;
int64_t ret;
int64_t ret = -1;

if (!bled_initialized) {
bb_error_msg("The library has not been initialized");
Expand Down Expand Up @@ -220,18 +219,16 @@ int64_t bled_uncompress_to_dir(const char* src, const char* dir, int type)

if (setjmp(bb_error_jmp))
goto err;

ret = unpacker[type](&xstate);
_close(xstate.src_fd);
if (xstate.dst_fd > 0)
_close(xstate.dst_fd);
return ret;

err:
free(xstate.dst_name);
if (xstate.src_fd > 0)
_close(xstate.src_fd);
if (xstate.dst_fd > 0)
_close(xstate.dst_fd);
return -1;
return ret;
}

int64_t bled_uncompress_from_buffer_to_buffer(const char* src, const size_t src_len, char* dst, size_t dst_len, int type)
Expand Down
2 changes: 1 addition & 1 deletion src/bled/decompress_bunzip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "bb_archive.h"

#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
# define dbg(...) bb_printf(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/bled/decompress_gunzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
error_msg = "corrupted data";
if (setjmp(error_jmp)) {
/* Error from deep inside zip machinery */
bb_simple_error_msg("corrupted data");
bb_simple_error_msg("%s", error_msg);
n = -1;
goto ret;
}
Expand Down Expand Up @@ -1272,7 +1272,7 @@ unpack_gz_stream(transformer_state_t *xstate)

n = inflate_unzip_internal(PASS_STATE xstate);
if (n < 0) {
total = (n == -ENOSPC)?xstate->mem_output_size_max:n;
total = (n == -ENOSPC) ? xstate->mem_output_size_max : n;
goto ret;
}
total += n;
Expand Down
Loading

0 comments on commit f233191

Please sign in to comment.