1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

g10/plaintext: disable estream buffering in binary mode

* g10/plaintext.c (handle_plaintext): Disable estream buffering in
binary modes.
--

Since in binary mode, large buffers are passed from source iobuf to
target estream, extra buffering in estream only causes extra memory
copying and overhead.

GnuPG-bug-id: T5828
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
This commit is contained in:
Jussi Kivilinna 2022-02-13 15:07:49 +02:00
parent f2322ff942
commit 583b664a07

View File

@ -292,7 +292,22 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
else /* Binary mode. */ else /* Binary mode. */
{ {
size_t temp_size = iobuf_set_buffer_size(0) * 1024; size_t temp_size = iobuf_set_buffer_size(0) * 1024;
byte *buffer = xmalloc (temp_size); byte *buffer;
if (fp)
{
/* Disable buffering in estream as we are passing large
* buffers to es_fwrite. */
es_setbuf (fp, NULL);
}
buffer = xmalloc (temp_size);
if (!buffer)
{
err = gpg_error_from_syserror ();
goto leave;
}
while (pt->len) while (pt->len)
{ {
int len = pt->len > temp_size ? temp_size : pt->len; int len = pt->len > temp_size ? temp_size : pt->len;
@ -371,6 +386,13 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
byte *buffer; byte *buffer;
int eof_seen = 0; int eof_seen = 0;
if (fp)
{
/* Disable buffering in estream as we are passing large
* buffers to es_fwrite. */
es_setbuf (fp, NULL);
}
buffer = xtrymalloc (temp_size); buffer = xtrymalloc (temp_size);
if (!buffer) if (!buffer)
{ {