To: vim_dev@googlegroups.com Subject: Patch 8.0.1620 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1620 Problem: Reading spell file has no good EOF detection. Solution: Check for EOF at every character read for a length field. Files: src/misc2.c *** ../vim-8.0.1619/src/misc2.c 2018-03-04 18:07:04.264592373 +0100 --- src/misc2.c 2018-03-20 12:27:42.804521060 +0100 *************** *** 6148,6206 **** #if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) /* * Read 2 bytes from "fd" and turn them into an int, MSB first. */ int get2c(FILE *fd) { ! int n; n = getc(fd); ! n = (n << 8) + getc(fd); ! return n; } /* * Read 3 bytes from "fd" and turn them into an int, MSB first. */ int get3c(FILE *fd) { ! int n; n = getc(fd); ! n = (n << 8) + getc(fd); ! n = (n << 8) + getc(fd); ! return n; } /* * Read 4 bytes from "fd" and turn them into an int, MSB first. */ int get4c(FILE *fd) { /* Use unsigned rather than int otherwise result is undefined * when left-shift sets the MSB. */ unsigned n; ! n = (unsigned)getc(fd); ! n = (n << 8) + (unsigned)getc(fd); ! n = (n << 8) + (unsigned)getc(fd); ! n = (n << 8) + (unsigned)getc(fd); return (int)n; } /* * Read 8 bytes from "fd" and turn them into a time_T, MSB first. */ time_T get8ctime(FILE *fd) { time_T n = 0; int i; for (i = 0; i < 8; ++i) ! n = (n << 8) + getc(fd); return n; } --- 6148,6230 ---- #if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) /* * Read 2 bytes from "fd" and turn them into an int, MSB first. + * Returns -1 when encountering EOF. */ int get2c(FILE *fd) { ! int c, n; n = getc(fd); ! if (n == EOF) return -1; ! c = getc(fd); ! if (c == EOF) return -1; ! return (n << 8) + c; } /* * Read 3 bytes from "fd" and turn them into an int, MSB first. + * Returns -1 when encountering EOF. */ int get3c(FILE *fd) { ! int c, n; n = getc(fd); ! if (n == EOF) return -1; ! c = getc(fd); ! if (c == EOF) return -1; ! n = (n << 8) + c; ! c = getc(fd); ! if (c == EOF) return -1; ! return (n << 8) + c; } /* * Read 4 bytes from "fd" and turn them into an int, MSB first. + * Returns -1 when encountering EOF. */ int get4c(FILE *fd) { + int c; /* Use unsigned rather than int otherwise result is undefined * when left-shift sets the MSB. */ unsigned n; ! c = getc(fd); ! if (c == EOF) return -1; ! n = (unsigned)c; ! c = getc(fd); ! if (c == EOF) return -1; ! n = (n << 8) + (unsigned)c; ! c = getc(fd); ! if (c == EOF) return -1; ! n = (n << 8) + (unsigned)c; ! c = getc(fd); ! if (c == EOF) return -1; ! n = (n << 8) + (unsigned)c; return (int)n; } /* * Read 8 bytes from "fd" and turn them into a time_T, MSB first. + * Returns -1 when encountering EOF. */ time_T get8ctime(FILE *fd) { + int c; time_T n = 0; int i; for (i = 0; i < 8; ++i) ! { ! c = getc(fd); ! if (c == EOF) return -1; ! n = (n << 8) + c; ! } return n; } *** ../vim-8.0.1619/src/version.c 2018-03-20 11:41:40.648367028 +0100 --- src/version.c 2018-03-20 12:28:27.896265272 +0100 *************** *** 768,769 **** --- 768,771 ---- { /* Add new patch number below this line */ + /**/ + 1620, /**/ -- Due knot trussed yore spell chequer two fined awl miss steaks. /// Bram Moolenaar -- Bram@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 ///