forked from aniani/vim
patch 8.0.1620: reading spell file has no good EOF detection
Problem: Reading spell file has no good EOF detection. Solution: Check for EOF at every character read for a length field.
This commit is contained in:
48
src/misc2.c
48
src/misc2.c
@@ -6148,59 +6148,83 @@ filewritable(char_u *fname)
|
|||||||
#if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO)
|
#if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* Read 2 bytes from "fd" and turn them into an int, MSB first.
|
* Read 2 bytes from "fd" and turn them into an int, MSB first.
|
||||||
|
* Returns -1 when encountering EOF.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
get2c(FILE *fd)
|
get2c(FILE *fd)
|
||||||
{
|
{
|
||||||
int n;
|
int c, n;
|
||||||
|
|
||||||
n = getc(fd);
|
n = getc(fd);
|
||||||
n = (n << 8) + getc(fd);
|
if (n == EOF) return -1;
|
||||||
return n;
|
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.
|
* Read 3 bytes from "fd" and turn them into an int, MSB first.
|
||||||
|
* Returns -1 when encountering EOF.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
get3c(FILE *fd)
|
get3c(FILE *fd)
|
||||||
{
|
{
|
||||||
int n;
|
int c, n;
|
||||||
|
|
||||||
n = getc(fd);
|
n = getc(fd);
|
||||||
n = (n << 8) + getc(fd);
|
if (n == EOF) return -1;
|
||||||
n = (n << 8) + getc(fd);
|
c = getc(fd);
|
||||||
return n;
|
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.
|
* Read 4 bytes from "fd" and turn them into an int, MSB first.
|
||||||
|
* Returns -1 when encountering EOF.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
get4c(FILE *fd)
|
get4c(FILE *fd)
|
||||||
{
|
{
|
||||||
|
int c;
|
||||||
/* Use unsigned rather than int otherwise result is undefined
|
/* Use unsigned rather than int otherwise result is undefined
|
||||||
* when left-shift sets the MSB. */
|
* when left-shift sets the MSB. */
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
n = (unsigned)getc(fd);
|
c = getc(fd);
|
||||||
n = (n << 8) + (unsigned)getc(fd);
|
if (c == EOF) return -1;
|
||||||
n = (n << 8) + (unsigned)getc(fd);
|
n = (unsigned)c;
|
||||||
n = (n << 8) + (unsigned)getc(fd);
|
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;
|
return (int)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read 8 bytes from "fd" and turn them into a time_T, MSB first.
|
* Read 8 bytes from "fd" and turn them into a time_T, MSB first.
|
||||||
|
* Returns -1 when encountering EOF.
|
||||||
*/
|
*/
|
||||||
time_T
|
time_T
|
||||||
get8ctime(FILE *fd)
|
get8ctime(FILE *fd)
|
||||||
{
|
{
|
||||||
|
int c;
|
||||||
time_T n = 0;
|
time_T n = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 8; ++i)
|
for (i = 0; i < 8; ++i)
|
||||||
n = (n << 8) + getc(fd);
|
{
|
||||||
|
c = getc(fd);
|
||||||
|
if (c == EOF) return -1;
|
||||||
|
n = (n << 8) + c;
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -766,6 +766,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1620,
|
||||||
/**/
|
/**/
|
||||||
1619,
|
1619,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user