Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Objects/bytearrayobject.c

Issue 24467: bytearray pop and remove Buffer Over-read
Patch Set: Created 4 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_bytes.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* PyByteArray (bytearray) implementation */ 1 /* PyByteArray (bytearray) implementation */
2 2
3 #define PY_SSIZE_T_CLEAN 3 #define PY_SSIZE_T_CLEAN
4 #include "Python.h" 4 #include "Python.h"
5 #include "structmember.h" 5 #include "structmember.h"
6 #include "bytes_methods.h" 6 #include "bytes_methods.h"
7 #include "bytesobject.h" 7 #include "bytesobject.h"
8 #include "pystrhex.h" 8 #include "pystrhex.h"
9 9
10 /*[clinic input] 10 /*[clinic input]
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 break; 884 break;
885 } 885 }
886 886
887 /* Interpret it as an int (__index__) */ 887 /* Interpret it as an int (__index__) */
888 rc = _getbytevalue(item, &value); 888 rc = _getbytevalue(item, &value);
889 Py_DECREF(item); 889 Py_DECREF(item);
890 if (!rc) 890 if (!rc)
891 goto error; 891 goto error;
892 892
893 /* Append the byte */ 893 /* Append the byte */
894 if (Py_SIZE(self) < self->ob_alloc) 894 if (Py_SIZE(self) + 1 < self->ob_alloc) {
895 Py_SIZE(self)++; 895 Py_SIZE(self)++;
896 PyByteArray_AS_STRING(self)[Py_SIZE(self)] = '\0';
897 }
896 else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0) 898 else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
897 goto error; 899 goto error;
898 PyByteArray_AS_STRING(self)[Py_SIZE(self)-1] = value; 900 PyByteArray_AS_STRING(self)[Py_SIZE(self)-1] = value;
899 } 901 }
900 902
901 /* Clean up and return success */ 903 /* Clean up and return success */
902 Py_DECREF(it); 904 Py_DECREF(it);
903 return 0; 905 return 0;
904 906
905 error: 907 error:
(...skipping 2377 matching lines...) Expand 10 before | Expand all | Expand 10 after
3283 } 3285 }
3284 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type); 3286 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type);
3285 if (it == NULL) 3287 if (it == NULL)
3286 return NULL; 3288 return NULL;
3287 it->it_index = 0; 3289 it->it_index = 0;
3288 Py_INCREF(seq); 3290 Py_INCREF(seq);
3289 it->it_seq = (PyByteArrayObject *)seq; 3291 it->it_seq = (PyByteArrayObject *)seq;
3290 _PyObject_GC_TRACK(it); 3292 _PyObject_GC_TRACK(it);
3291 return (PyObject *)it; 3293 return (PyObject *)it;
3292 } 3294 }
OLDNEW
« no previous file with comments | « Lib/test/test_bytes.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+