To: vim-dev@vim.org Subject: patch 7.0.231 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 7.0.231 Problem: When recovering from a swap file the page size is likely to be different from the minimum. The block used for the first page then has a buffer of the wrong size, causing a crash when it's reused later. (Zephaniah Hull) Solution: Reallocate the buffer when the page size changes. Also check that the page size is at least the minimum value. Files: src/memline.c *** ../vim-7.0.230/src/memline.c Tue Mar 6 20:27:03 2007 --- src/memline.c Thu Apr 19 16:10:39 2007 *************** *** 1015,1032 **** --- 1015,1053 ---- msg_end(); goto theend; } + /* * If we guessed the wrong page size, we have to recalculate the * highest block number in the file. */ if (mfp->mf_page_size != (unsigned)char_to_long(b0p->b0_page_size)) { + unsigned previous_page_size = mfp->mf_page_size; + mf_new_page_size(mfp, (unsigned)char_to_long(b0p->b0_page_size)); + if (mfp->mf_page_size < previous_page_size) + { + msg_start(); + msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST); + MSG_PUTS_ATTR(_(" has been damaged (page size is smaller than minimum value).\n"), + attr | MSG_HIST); + msg_end(); + goto theend; + } if ((size = lseek(mfp->mf_fd, (off_t)0L, SEEK_END)) <= 0) mfp->mf_blocknr_max = 0; /* no file or empty file */ else mfp->mf_blocknr_max = (blocknr_T)(size / mfp->mf_page_size); mfp->mf_infile_count = mfp->mf_blocknr_max; + + /* need to reallocate the memory used to store the data */ + p = alloc(mfp->mf_page_size); + if (p == NULL) + goto theend; + mch_memmove(p, hp->bh_data, previous_page_size); + vim_free(hp->bh_data); + hp->bh_data = p; + b0p = (ZERO_BL *)(hp->bh_data); } /* *** ../vim-7.0.230/src/version.c Thu Apr 26 17:08:16 2007 --- src/version.c Thu Apr 26 17:11:38 2007 *************** *** 668,669 **** --- 668,671 ---- { /* Add new patch number below this line */ + /**/ + 231, /**/ -- hundred-and-one symptoms of being an internet addict: 23. You can't call your mother...she doesn't have a modem. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ download, build and distribute -- http://www.A-A-P.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///