| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,6 +96,13 @@ def test_new_features(self): | |||
| 96 | 96 | ('10s', b'helloworld', b'helloworld', b'helloworld', 0), | |
| 97 | 97 | ('11s', b'helloworld', b'helloworld\0', b'helloworld\0', 1), | |
| 98 | 98 | ('20s', b'helloworld', b'helloworld'+10*b'\0', b'helloworld'+10*b'\0', 1), | |
| 99 | + ('0p', b'helloworld', b'', b'', 1), | ||
| 100 | + ('1p', b'helloworld', b'\x00', b'\x00', 1), | ||
| 101 | + ('2p', b'helloworld', b'\x01h', b'\x01h', 1), | ||
| 102 | + ('10p', b'helloworld', b'\x09helloworl', b'\x09helloworl', 1), | ||
| 103 | + ('11p', b'helloworld', b'\x0Ahelloworld', b'\x0Ahelloworld', 0), | ||
| 104 | + ('12p', b'helloworld', b'\x0Ahelloworld\0', b'\x0Ahelloworld\0', 1), | ||
| 105 | + ('20p', b'helloworld', b'\x0Ahelloworld'+9*b'\0', b'\x0Ahelloworld'+9*b'\0', 1), | ||
| 99 | 106 | ('b', 7, b'\7', b'\7', 0), | |
| 100 | 107 | ('b', -7, b'\371', b'\371', 0), | |
| 101 | 108 | ('B', 7, b'\7', b'\7', 0), | |
@@ -339,6 +346,7 @@ def assertStructError(func, *args, **kwargs): | |||
| 339 | 346 | def test_p_code(self): | |
| 340 | 347 | # Test p ("Pascal string") code. | |
| 341 | 348 | for code, input, expected, expectedback in [ | |
| 349 | + ('0p', b'abc', b'', b''), | ||
| 342 | 350 | ('p', b'abc', b'\x00', b''), | |
| 343 | 351 | ('1p', b'abc', b'\x00', b''), | |
| 344 | 352 | ('2p', b'abc', b'\x01a', b'a'), | |
@@ -580,6 +588,7 @@ def test__sizeof__(self): | |||
| 580 | 588 | self.check_sizeof('187s', 1) | |
| 581 | 589 | self.check_sizeof('20p', 1) | |
| 582 | 590 | self.check_sizeof('0s', 1) | |
| 591 | + self.check_sizeof('0p', 1) | ||
| 583 | 592 | self.check_sizeof('0c', 0) | |
| 584 | 593 | ||
| 585 | 594 | def test_boundary_error_message(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1653,6 +1653,7 @@ Scott Schram | |||
| 1653 | 1653 | Robin Schreiber | |
| 1654 | 1654 | Chad J. Schroeder | |
| 1655 | 1655 | Simon-Martin Schroeder | |
| 1656 | + Brian Schubert | ||
| 1656 | 1657 | Christian Schubert | |
| 1657 | 1658 | Sam Schulenburg | |
| 1658 | 1659 | Andreas Schwab | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fixed potential crash when using :mod:`struct` to process zero-width | ||
| 2 | + 'Pascal string' fields (``0p``). | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1669,9 +1669,16 @@ s_unpack_internal(PyStructObject *soself, const char *startfrom, | |||
| 1669 | 1669 | if (e->format == 's') { | |
| 1670 | 1670 | v = PyBytes_FromStringAndSize(res, code->size); | |
| 1671 | 1671 | } else if (e->format == 'p') { | |
| 1672 | - Py_ssize_t n = *(unsigned char*)res; | ||
| 1673 | - if (n >= code->size) | ||
| 1674 | - n = code->size - 1; | ||
| 1672 | + Py_ssize_t n; | ||
| 1673 | + if (code->size == 0) { | ||
| 1674 | + n = 0; | ||
| 1675 | + } | ||
| 1676 | + else { | ||
| 1677 | + n = *(unsigned char*)res; | ||
| 1678 | + if (n >= code->size) { | ||
| 1679 | + n = code->size - 1; | ||
| 1680 | + } | ||
| 1681 | + } | ||
| 1675 | 1682 | v = PyBytes_FromStringAndSize(res + 1, n); | |
| 1676 | 1683 | } else { | |
| 1677 | 1684 | v = e->unpack(state, res, e); | |
@@ -1982,8 +1989,12 @@ s_pack_internal(PyStructObject *soself, PyObject *const *args, int offset, | |||
| 1982 | 1989 | n = PyByteArray_GET_SIZE(v); | |
| 1983 | 1990 | p = PyByteArray_AS_STRING(v); | |
| 1984 | 1991 | } | |
| 1985 | - if (n > (code->size - 1)) | ||
| 1992 | + if (code->size == 0) { | ||
| 1993 | + n = 0; | ||
| 1994 | + } | ||
| 1995 | + else if (n > (code->size - 1)) { | ||
| 1986 | 1996 | n = code->size - 1; | |
| 1997 | + } | ||
| 1987 | 1998 | if (n > 0) | |
| 1988 | 1999 | memcpy(res + 1, p, n); | |
| 1989 | 2000 | if (n > 255) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments