Skip to content

Commit

Permalink
[2.7] bpo-36149 Fix potential use of uninitialized memory in cPickle (#…
Browse files Browse the repository at this point in the history
…12105)

Fix off-by-one bug in cPickle that caused it to use uninitialised memory on truncated pickles read from FILE*s.
  • Loading branch information
Yhg1s committed Mar 4, 2019
1 parent 84b5ac9 commit d9bf7f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
@@ -0,0 +1,2 @@
Fix use of uninitialized memory in cPickle when reading a truncated pickle
from a file object.
13 changes: 8 additions & 5 deletions Modules/cPickle.c
Expand Up @@ -586,12 +586,15 @@ readline_file(Unpicklerobject *self, char **s)
while (1) {
Py_ssize_t bigger;
char *newbuf;
for (; i < (self->buf_size - 1); i++) {
if (feof(self->fp) ||
(self->buf[i] = getc(self->fp)) == '\n') {
self->buf[i + 1] = '\0';
while (i < (self->buf_size - 1)) {
int newchar = getc(self->fp);
if (newchar != EOF) {
self->buf[i++] = newchar;
}
if (newchar == EOF || newchar == '\n') {
self->buf[i] = '\0';
*s = self->buf;
return i + 1;
return i;
}
}
if (self->buf_size > (PY_SSIZE_T_MAX >> 1)) {
Expand Down

0 comments on commit d9bf7f4

Please sign in to comment.