mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
gpg: Detect already compressed data also when using a pipe.
* common/iobuf.c (file_filter_ctx_t): Add fields for the peek feature.
(file_filter): Implement peeking.
(iobuf_ioctl): Add new IOBUF_IOCTL_PEEK.
* common/iobuf.h (IOBUF_IOCTL_PEEK, IOBUFCTRL_PEEK): New.
* common/miscellaneous.c (is_file_compressed): Rewrite. Detect PDF.
* g10/encrypt.c (encrypt_simple): Peek before detecting compression.
(encrypt_crypt): Ditto.
* g10/sign.c (sign_file): Also detect already compressed data.
* g10/options.h (opt): Add explicit_compress_option.
* g10/gpg.c (main): Set opt.explicit_compress_option for -z.
--
Note that this patch also introduces a compression check for signing
which was never done in the past.
GnuPG-bug-id: 6332
Backported-from-master: 60963d98cf
Note that sign.c (sign_file) has been re-indented to ease future
backports.
This commit is contained in:
parent
ca822a2339
commit
ce8ffd71b7
9 changed files with 491 additions and 347 deletions
|
@ -1,7 +1,7 @@
|
|||
/* encrypt.c - Main encryption driver
|
||||
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
* 2006, 2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2016, 2022 g10 Code GmbH
|
||||
* Copyright (C) 2016, 2022, 2023 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -17,6 +17,7 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -326,6 +327,8 @@ encrypt_simple (const char *filename, int mode, int use_seskey)
|
|||
text_filter_context_t tfx;
|
||||
progress_filter_context_t *pfx;
|
||||
int do_compress = !!default_compress_algo();
|
||||
char peekbuf[32];
|
||||
int peekbuflen;
|
||||
|
||||
if (!gnupg_rng_is_compliant (opt.compliance))
|
||||
{
|
||||
|
@ -362,6 +365,14 @@ encrypt_simple (const char *filename, int mode, int use_seskey)
|
|||
return rc;
|
||||
}
|
||||
|
||||
peekbuflen = iobuf_ioctl (inp, IOBUF_IOCTL_PEEK, sizeof peekbuf, peekbuf);
|
||||
if (peekbuflen < 0)
|
||||
{
|
||||
peekbuflen = 0;
|
||||
if (DBG_FILTER)
|
||||
log_debug ("peeking at input failed\n");
|
||||
}
|
||||
|
||||
handle_progress (pfx, inp, filename);
|
||||
|
||||
if (opt.textmode)
|
||||
|
@ -426,10 +437,11 @@ encrypt_simple (const char *filename, int mode, int use_seskey)
|
|||
if (do_compress
|
||||
&& cfx.dek
|
||||
&& (cfx.dek->use_mdc || cfx.dek->use_aead)
|
||||
&& is_file_compressed(filename, &rc))
|
||||
&& !opt.explicit_compress_option
|
||||
&& is_file_compressed (peekbuf, peekbuflen))
|
||||
{
|
||||
if (opt.verbose)
|
||||
log_info(_("'%s' already compressed\n"), filename);
|
||||
log_info(_("'%s' already compressed\n"), filename? filename: "[stdin]");
|
||||
do_compress = 0;
|
||||
}
|
||||
|
||||
|
@ -768,6 +780,8 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
|
|||
progress_filter_context_t *pfx;
|
||||
PK_LIST pk_list;
|
||||
int do_compress;
|
||||
char peekbuf[32];
|
||||
int peekbuflen;
|
||||
|
||||
if (filefd != -1 && filename)
|
||||
return gpg_error (GPG_ERR_INV_ARG); /* Both given. */
|
||||
|
@ -840,6 +854,14 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
|
|||
if (opt.verbose)
|
||||
log_info (_("reading from '%s'\n"), iobuf_get_fname_nonnull (inp));
|
||||
|
||||
peekbuflen = iobuf_ioctl (inp, IOBUF_IOCTL_PEEK, sizeof peekbuf, peekbuf);
|
||||
if (peekbuflen < 0)
|
||||
{
|
||||
peekbuflen = 0;
|
||||
if (DBG_FILTER)
|
||||
log_debug ("peeking at input failed\n");
|
||||
}
|
||||
|
||||
handle_progress (pfx, inp, filename);
|
||||
|
||||
if (opt.textmode)
|
||||
|
@ -874,10 +896,11 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
|
|||
|
||||
if (do_compress
|
||||
&& (cfx.dek->use_mdc || cfx.dek->use_aead)
|
||||
&& is_file_compressed(filename, &rc2))
|
||||
&& !opt.explicit_compress_option
|
||||
&& is_file_compressed (peekbuf, peekbuflen))
|
||||
{
|
||||
if (opt.verbose)
|
||||
log_info(_("'%s' already compressed\n"), filename);
|
||||
log_info(_("'%s' already compressed\n"), filename? filename: "[stdin]");
|
||||
do_compress = 0;
|
||||
}
|
||||
if (rc2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue