From 88dcf266463a99bfd94304aa6da9be8b2c7b389a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 7 May 2004 09:32:53 +0000 Subject: [PATCH] (write_plaintext_packet): Fixed the detection of too large files in the same way as in encode.c. --- g10/ChangeLog | 5 +++++ g10/sign.c | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index b180b25d9..ac1459295 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2004-05-07 Werner Koch + + * sign.c (write_plaintext_packet): Fixed the detection of too + large files in the same way as in encode.c. + 2004-04-22 David Shaw * keygen.c (make_backsig): If DO_BACKSIGS is not defined, do not diff --git a/g10/sign.c b/g10/sign.c index 1824060c2..db458236f 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -467,19 +467,24 @@ write_plaintext_packet (IOBUF out, IOBUF inp, const char *fname, int ptmode) /* try to calculate the length of the data */ if (fname && *fname && !(*fname=='-' && !fname[1])) { - if( !(filesize = iobuf_get_filelength(inp)) ) + off_t tmpsize; + + if( !(tmpsize = iobuf_get_filelength(inp)) ) log_info (_("WARNING: `%s' is an empty file\n"), fname); - /* we can't yet encode the length of very large files, - * so we switch to partial length encoding in this case */ - if (filesize >= IOBUF_FILELENGTH_LIMIT) - filesize = 0; + /* We can't encode the length of very large files because + OpenPGP uses only 32 bit for file sizes. So if the size of + a file is larger than 2^32 minus some bytes for packet + headers, we switch to partial length encoding. */ + if ( tmpsize < (IOBUF_FILELENGTH_LIMIT - 65536) ) + filesize = tmpsize; + else + filesize = 0; - /* because the text_filter modifies the length of the + /* Because the text_filter modifies the length of the * data, it is not possible to know the used length * without a double read of the file - to avoid that - * we simple use partial length packets. - */ + * we simple use partial length packets. */ if ( ptmode == 't' ) filesize = 0; }