issue1597011: Fix for bz2 module corner-case error due to error checking bug.
This commit is contained in:
parent
5cf6ef84b9
commit
b5ec5876f2
|
@ -235,6 +235,7 @@ Util_GetLine(BZ2FileObject *f, int n)
|
||||||
size_t increment; /* amount to increment the buffer */
|
size_t increment; /* amount to increment the buffer */
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
int bzerror;
|
int bzerror;
|
||||||
|
int bytes_read;
|
||||||
int newlinetypes = f->f_newlinetypes;
|
int newlinetypes = f->f_newlinetypes;
|
||||||
int skipnextlf = f->f_skipnextlf;
|
int skipnextlf = f->f_skipnextlf;
|
||||||
int univ_newline = f->f_univ_newline;
|
int univ_newline = f->f_univ_newline;
|
||||||
|
@ -249,24 +250,22 @@ Util_GetLine(BZ2FileObject *f, int n)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
if (univ_newline) {
|
while (buf != end) {
|
||||||
while (1) {
|
bytes_read = BZ2_bzRead(&bzerror, f->fp, &c, 1);
|
||||||
BZ2_bzRead(&bzerror, f->fp, &c, 1);
|
|
||||||
f->pos++;
|
f->pos++;
|
||||||
if (bzerror != BZ_OK || buf == end)
|
if (bytes_read == 0) break;
|
||||||
break;
|
if (univ_newline) {
|
||||||
if (skipnextlf) {
|
if (skipnextlf) {
|
||||||
skipnextlf = 0;
|
skipnextlf = 0;
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
/* Seeing a \n here with
|
/* Seeing a \n here with skipnextlf true means we
|
||||||
* skipnextlf true means we
|
|
||||||
* saw a \r before.
|
* saw a \r before.
|
||||||
*/
|
*/
|
||||||
newlinetypes |= NEWLINE_CRLF;
|
newlinetypes |= NEWLINE_CRLF;
|
||||||
BZ2_bzRead(&bzerror, f->fp,
|
if (bzerror != BZ_OK) break;
|
||||||
&c, 1);
|
bytes_read = BZ2_bzRead(&bzerror, f->fp, &c, 1);
|
||||||
if (bzerror != BZ_OK)
|
f->pos++;
|
||||||
break;
|
if (bytes_read == 0) break;
|
||||||
} else {
|
} else {
|
||||||
newlinetypes |= NEWLINE_CR;
|
newlinetypes |= NEWLINE_CR;
|
||||||
}
|
}
|
||||||
|
@ -276,17 +275,12 @@ Util_GetLine(BZ2FileObject *f, int n)
|
||||||
c = '\n';
|
c = '\n';
|
||||||
} else if (c == '\n')
|
} else if (c == '\n')
|
||||||
newlinetypes |= NEWLINE_LF;
|
newlinetypes |= NEWLINE_LF;
|
||||||
*buf++ = c;
|
|
||||||
if (c == '\n') break;
|
|
||||||
}
|
}
|
||||||
if (bzerror == BZ_STREAM_END && skipnextlf)
|
|
||||||
newlinetypes |= NEWLINE_CR;
|
|
||||||
} else /* If not universal newlines use the normal loop */
|
|
||||||
do {
|
|
||||||
BZ2_bzRead(&bzerror, f->fp, &c, 1);
|
|
||||||
f->pos++;
|
|
||||||
*buf++ = c;
|
*buf++ = c;
|
||||||
} while (bzerror == BZ_OK && c != '\n' && buf != end);
|
if (bzerror != BZ_OK || c == '\n') break;
|
||||||
|
}
|
||||||
|
if (univ_newline && bzerror == BZ_STREAM_END && skipnextlf)
|
||||||
|
newlinetypes |= NEWLINE_CR;
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
f->f_newlinetypes = newlinetypes;
|
f->f_newlinetypes = newlinetypes;
|
||||||
f->f_skipnextlf = skipnextlf;
|
f->f_skipnextlf = skipnextlf;
|
||||||
|
|
Loading…
Reference in New Issue