Skip to content

Commit 65aee0b

Browse files
committed
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Problem: Crash when switching 'cryptmethod' to xchaha20 with an existing undo file. (Martin Tournoij) Solution: Disable reading undo file when decoding can't be done inplace. (issue #8467)
1 parent 4cd5c52 commit 65aee0b

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/bufwrite.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,16 @@ buf_write_bytes(struct bw_info *ip)
494494
if (crypt_works_inplace(ip->bw_buffer->b_cryptstate))
495495
{
496496
# endif
497-
crypt_encode_inplace(ip->bw_buffer->b_cryptstate, buf, len, ip->bw_finish);
497+
crypt_encode_inplace(ip->bw_buffer->b_cryptstate, buf, len,
498+
ip->bw_finish);
498499
# ifdef CRYPT_NOT_INPLACE
499500
}
500501
else
501502
{
502503
char_u *outbuf;
503504

504-
len = crypt_encode_alloc(curbuf->b_cryptstate, buf, len, &outbuf, ip->bw_finish);
505+
len = crypt_encode_alloc(curbuf->b_cryptstate, buf, len, &outbuf,
506+
ip->bw_finish);
505507
if (len == 0)
506508
return OK; // Crypt layer is buffering, will flush later.
507509
wlen = write_eintr(ip->bw_fd, outbuf, len);
@@ -1980,10 +1982,18 @@ buf_write(
19801982
write_info.bw_start_lnum = start;
19811983

19821984
#ifdef FEAT_PERSISTENT_UNDO
1985+
// TODO: if the selected crypt method prevents the undo file from being
1986+
// written, and existing undo file should be deleted.
19831987
write_undo_file = (buf->b_p_udf
19841988
&& overwriting
19851989
&& !append
19861990
&& !filtering
1991+
# ifdef CRYPT_NOT_INPLACE
1992+
// writing undo file requires
1993+
// crypt_encode_inplace()
1994+
&& (curbuf->b_cryptstate == NULL
1995+
|| crypt_works_inplace(curbuf->b_cryptstate))
1996+
# endif
19871997
&& reset_changed
19881998
&& !checking_conversion);
19891999
if (write_undo_file)

src/fileio.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,9 +1298,17 @@ readfile(
12981298
* At start of file: Check for magic number of encryption.
12991299
*/
13001300
if (filesize == 0 && size > 0)
1301+
{
13011302
cryptkey = check_for_cryptkey(cryptkey, ptr, &size,
13021303
&filesize, newfile, sfname,
13031304
&did_ask_for_key);
1305+
# ifdef CRYPT_NOT_INPLACE
1306+
if (curbuf->b_cryptstate != NULL
1307+
&& !crypt_works_inplace(curbuf->b_cryptstate))
1308+
// reading undo file requires crypt_decode_inplace()
1309+
read_undo_file = FALSE;
1310+
# endif
1311+
}
13041312
/*
13051313
* Decrypt the read bytes. This is done before checking for
13061314
* EOF because the crypt layer may be buffering.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3063,
758760
/**/
759761
3062,
760762
/**/

0 commit comments

Comments
 (0)