Re: Re:Re: Blowfish[2] failed to encrypt big text file of 24MB

47 views
Skip to first unread message

Ken Takata

unread,
Dec 18, 2015, 9:01:54 AM12/18/15
to vim_use, fritzo...@gmail.com, mig...@126.com, vim...@vim.org
Hi,

2015/2/14 Sat 6:04:00 UTC+9 Bram Moolenaar wrote:
> Ben Fritz wrote:
>
> > On Friday, February 13, 2015 at 4:16:01 AM UTC-6, might1 wrote:
> > > At 2015-02-13 18:00:32,"might1" <mig...@126.com> wrote:
> > > > Right now, I just tried vim7.4 downloaded from www.vim.org.
> > > According to your way, I tried in commanld line 'vim -u NONE -N
> > > test.txt'   and  'gvim -u NONE -N test.txt' to encrypt with blowfish
> > > method, both failed. The resulting files all growed to 113MB. Really
> > > strange! No error jumped out.
> > >
> > > Do you need I attach the resulting encrypted file whose size remains 113MB after max compression?
> > >
> >
> > Actually, attaching the already encrypted file is pretty much useless.
> >
> > I experimented some, with the attached toy input file (compressed with 7-zip to avoid a huge attachment), and found that the issue seems to be related to writing *new* files somehow.
> >
> > If I create an encrypted output file as follows, everything works fine:
> >
> > :e encrypt_in.txt
> > :saveas encrypt_blowfish2.txt
> > :X
> > password
> > password
> > :w
> >
> > However, if I encrypt as follows, I see the E381 error repeated a bunch of times, and Vim seems to hang if I quit that error and try the password again and write, presumably creating that giant file the OP mentioned:
> >
> > :r encrypt_in.txt
> > ggdd
> > :X
> > password
> > password
> > :w encrypt_blowfish2.txt
> >
> > Oddly enough, this also fails:
> >
> > :r encrypt_in.txt
> > ggdd
> > :w encrypt_blowfish2.txt
> > :X
> > password
> > password
> > :w
> >
> > But this succeeds (after a really long time):
> >
> > :r encrypt_in.txt
> > ggdd
> > :w encrypt_blowfish2.txt
> > :e
> > :X
> > password
> > password
> > :w
> >
> > It seems to be related to encrypting the swapfile for the new file. This fails:
> >
> > :set swapfile noundofile
> > :r encrypt_in.txt
> > ggdd
> > :X
> > password
> > password
> > :w encrypt_blowfish2.txt
> >
> > But this succeeds:
> >
> > :set noswapfile undofile
> > :r encrypt_in.txt
> > ggdd
> > :X
> > password
> > password
> > :w encrypt_blowfish2.txt
> >
> > Using the following Vim version on Windows 7:
> >
> > VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Feb 4 2015 10:16:41)
> > MS-Windows 64-bit GUI version with OLE support
> > Included patches: 1-608
>
> [...]
>
> Since it works fine on Linux, could it be related to "long" not being
> able to store a pointer? It's a common problem for porting a C program
> to Windows.

Perhaps I found a fix for this.

--- a/src/memfile.c
+++ b/src/memfile.c
@@ -1033,7 +1033,7 @@

#ifdef FEAT_CRYPT
/* Decrypt if 'key' is set and this is a data block. */
- if (*mfp->mf_buffer->b_p_key != NUL)
+ if (*mfp->mf_buffer->b_p_key != NUL || mfp->mf_old_key != NULL)
ml_decrypt_data(mfp, hp->bh_data, offset, size);
#endif

@@ -1136,7 +1136,7 @@

#ifdef FEAT_CRYPT
/* Encrypt if 'key' is set and this is a data block. */
- if (*mfp->mf_buffer->b_p_key != NUL)
+ if (*mfp->mf_buffer->b_p_key != NUL || mfp->mf_old_key != NULL)
{
data = ml_encrypt_data(mfp, data, offset, size);
if (data == NULL)


I checked this only on Windows (but not well).
I hope someone check this more deeply.
I wonder why the problem doesn't occur on Linux.

Regards,
Ken Takata

Ben Fritz

unread,
Dec 18, 2015, 1:42:17 PM12/18/15
to vim_use, fritzo...@gmail.com, mig...@126.com, vim...@vim.org
On Friday, December 18, 2015 at 8:01:37 AM UTC-6, Ken Takata wrote:
> > > However, if I encrypt as follows, I see the E381 error repeated a bunch of times, and Vim seems to hang if I quit that error and try the password again and write, presumably creating that giant file the OP mentioned:
> > >
> > > :r encrypt_in.txt
> > > ggdd
> > > :X
> > > password
> > > password
> > > :w encrypt_blowfish2.txt
> > >
>
> Perhaps I found a fix for this.
>
> --- a/src/memfile.c
> +++ b/src/memfile.c
> @@ -1033,7 +1033,7 @@
>

Unfortunately, I can no longer reproduce the issue: I was able to encrypt, save, quit, read, and decrypt in Vim 7.4.977 (still HUGE 64-bit on Windows 7) using the previously failing methods above.

So I'm not able to test whether your patch fixes it. :-(

Christian Brabandt

unread,
Dec 18, 2015, 2:24:00 PM12/18/15
to vim_use, vim...@vim.org
On Fr, 18 Dez 2015, Ken Takata wrote:

> Perhaps I found a fix for this.

Wasn't this fixes with 7.4.730?



Best,
Christian
--
Fußball ist wie Schach nur ohne Würfel.
-- Lukas Podolski

Bram Moolenaar

unread,
Dec 18, 2015, 2:47:19 PM12/18/15
to Ken Takata, vim_use, fritzo...@gmail.com, mig...@126.com, vim...@vim.org
It's most likely related to the memory limit, causing Vim to use the
swap file.

> Perhaps I found a fix for this.

Thanks! Although I think only the first part matters, when writing the
old key isn't used.

--
If I tell you "you have a beautiful body", would you hold it against me?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ken Takata

unread,
Dec 18, 2015, 7:17:42 PM12/18/15
to vim_dev, ktakat...@gmail.com, vim...@googlegroups.com, fritzo...@gmail.com, mig...@126.com
Hi Bram,
Ah, you are right!
I confirmed that the second part was not needed.

Regards,
Ken Takata

Ken Takata

unread,
Dec 18, 2015, 7:21:33 PM12/18/15
to vim_dev, vim...@googlegroups.com
Hi Christian,

2015/12/19 Sat 4:24:00 UTC+9 Christian Brabandt wrote:
> On Fr, 18 Dez 2015, Ken Takata wrote:
>
> > Perhaps I found a fix for this.
>
> Wasn't this fixes with 7.4.730?

Unfortunately, it wasn't.

Regards,
Ken Takata

Reply all
Reply to author
Forward
0 new messages