aboutsummaryrefslogtreecommitdiffstats
path: root/g10/sign.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2023-01-18 17:04:50 +0000
committerWerner Koch <[email protected]>2023-01-19 09:45:54 +0000
commit60963d98cfd8e60f88ee43c2d992f6dd3bbbd74c (patch)
tree766f37c0531a72f5d11e3920b87ba2e51ce23b46 /g10/sign.c
parentcommon: Replace all assert by log_assert. (diff)
downloadgnupg-60963d98cfd8e60f88ee43c2d992f6dd3bbbd74c.tar.gz
gnupg-60963d98cfd8e60f88ee43c2d992f6dd3bbbd74c.zip
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
Diffstat (limited to 'g10/sign.c')
-rw-r--r--g10/sign.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/g10/sign.c b/g10/sign.c
index 385254987..a66410ebd 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -1037,6 +1037,9 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
int multifile = 0;
u32 duration=0;
pt_extra_hash_data_t extrahash = NULL;
+ char peekbuf[32];
+ int peekbuflen = 0;
+
pfx = new_progress_context ();
afx = new_armor_context ();
@@ -1095,6 +1098,14 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
goto leave;
}
+ 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, fname);
}
@@ -1251,8 +1262,14 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
{
int compr_algo = opt.compress_algo;
- /* If not forced by user */
- if (compr_algo==-1)
+ if (!opt.explicit_compress_option
+ && is_file_compressed (peekbuf, peekbuflen))
+ {
+ if (opt.verbose)
+ log_info(_("'%s' already compressed\n"), fname? fname: "[stdin]");
+ compr_algo = 0;
+ }
+ else if (compr_algo==-1)
{
/* If we're not encrypting, then select_algo_from_prefs
* will fail and we'll end up with the default. If we are