<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/py/modstruct.c, branch 6.0.1</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.0.1</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.0.1'/>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/'/>
<updated>2020-09-12T19:07:23+00:00</updated>
<entry>
<title>modstruct: Improve compliance with python3</title>
<updated>2020-09-12T19:07:23+00:00</updated>
<author>
<name>Jeff Epler</name>
<email>jepler@gmail.com</email>
</author>
<published>2020-09-12T18:57:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=54d97251fe2dd4939652a186bf703885e654b4d1'/>
<id>urn:sha1:54d97251fe2dd4939652a186bf703885e654b4d1</id>
<content type='text'>
While checking whether we can enable -Wimplicit-fallthrough, I encountered
a diagnostic in mp_binary_set_val_array_from_int which led to discovering
the following bug:
```
&gt;&gt;&gt; struct.pack("xb", 3)
b'\x03\x03'
```
That is, the next value (3) was used as the value of a padding byte, while
standard Python always fills "x" bytes with zeros.  I initially thought
this had to do with the unintentional fallthrough, but it doesn't.
Instead, this code would relate to an array.array with a typecode of
padding ('x'), which is ALSO not desktop Python compliant:
```
&gt;&gt;&gt; array.array('x', (1, 2, 3))
array('x', [1, 0, 0])
```
Possibly this is dead code that used to be shared between struct-setting
and array-setting, but it no longer is.

I also discovered that the argument list length for struct.pack
and struct.pack_into were not checked, and that the length of binary data
passed to array.array was not checked to be a multiple of the element
size.

I have corrected all of these to conform more closely to standard Python
and revised some tests where necessary.  Some tests for micropython-specific
behavior that does not conform to standard Python and is not present
in CircuitPython was deleted outright.
</content>
</entry>
<entry>
<title>Add license to some obvious files.</title>
<updated>2020-07-06T18:16:25+00:00</updated>
<author>
<name>Diego Elio Pettenò</name>
<email>flameeyes@flameeyes.com</email>
</author>
<published>2020-06-03T22:40:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=34b4993d63a6b576f29d624385c681f679b4124c'/>
<id>urn:sha1:34b4993d63a6b576f29d624385c681f679b4124c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Improve struct compatibility with CPython</title>
<updated>2019-01-20T20:12:34+00:00</updated>
<author>
<name>Dan Halbert</name>
<email>halbert@halwitz.org</email>
</author>
<published>2019-01-20T20:10:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=7a09af73ec7f4a11a1404dff6276e09072d06983'/>
<id>urn:sha1:7a09af73ec7f4a11a1404dff6276e09072d06983</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Support internationalisation.</title>
<updated>2018-08-07T21:58:57+00:00</updated>
<author>
<name>Scott Shawcroft</name>
<email>scott@tannewt.org</email>
</author>
<published>2018-07-31T23:53:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=933add6cd833bb6ba6682ad2b6eb478871415ff5'/>
<id>urn:sha1:933add6cd833bb6ba6682ad2b6eb478871415ff5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py/modstruct: Check and prevent buffer-write overflow in struct packing.</title>
<updated>2017-09-01T01:11:09+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-09-01T01:11:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=2daacc5ceef7e36ac3c88b8946088b6b3513993b'/>
<id>urn:sha1:2daacc5ceef7e36ac3c88b8946088b6b3513993b</id>
<content type='text'>
Prior to this patch, the size of the buffer given to pack_into() was checked
for being too small by using the count of the arguments, not their actual
size.  For example, a format spec of '4I' would only check that there was 4
bytes available, not 16; and 'I' would check for 1 byte, not 4.

The pack() function is ok because its buffer is created to be exactly the
correct size.

The fix in this patch calculates the total size of the format spec at the
start of pack_into() and verifies that the buffer is large enough.  This
adds some computational overhead, to iterate through the whole format spec.
The alternative is to check during the packing, but that requires extra
code to handle alignment, and the check is anyway not needed for pack().
So to maintain minimal code size the check is done using struct_calcsize.
</content>
</entry>
<entry>
<title>py/modstruct: Check and prevent buffer-read overflow in struct unpacking</title>
<updated>2017-09-01T00:53:29+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-09-01T00:53:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=79d5acbd01fed21e1c8e46b06690072375de0bfe'/>
<id>urn:sha1:79d5acbd01fed21e1c8e46b06690072375de0bfe</id>
<content type='text'>
Prior to this patch, the size of the buffer given to unpack/unpack_from was
checked for being too small by using the count of the arguments, not their
actual size.  For example, a format spec of '4I' would only check that
there was 4 bytes available, not 16; and 'I' would check for 1 byte, not 4.

This bug is fixed in this patch by calculating the total size of the format
spec at the start of the unpacking function.  This function anyway needs to
calculate the number of items at the start, so calculating the total size
can be done at the same time.
</content>
</entry>
<entry>
<title>py/modstruct: In struct.pack, stop converting if there are no args left.</title>
<updated>2017-09-01T00:10:51+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-09-01T00:10:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=793d826d9df67c3f544505beda63ca36d8dfa1c4'/>
<id>urn:sha1:793d826d9df67c3f544505beda63ca36d8dfa1c4</id>
<content type='text'>
This patch makes a repeat counter behave the same as repeating the
typecode, when there are not enough args.  For example:
struct.pack('2I', 1) now behave the same as struct.pack('II', 1).
</content>
</entry>
<entry>
<title>all: Use the name MicroPython consistently in comments</title>
<updated>2017-07-31T08:35:40+00:00</updated>
<author>
<name>Alexander Steffen</name>
<email>devel.20.webmeister@spamgourmet.com</email>
</author>
<published>2017-06-30T07:22:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=55f33240f3d7051d4213629e92437a36f1fac50e'/>
<id>urn:sha1:55f33240f3d7051d4213629e92437a36f1fac50e</id>
<content type='text'>
There were several different spellings of MicroPython present in comments,
when there should be only one.
</content>
</entry>
<entry>
<title>py/binary: mp_binary_get_size: Raise error on unsupported typecodes.</title>
<updated>2017-01-17T19:53:06+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2017-01-17T19:50:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=af9046193148084f008501434e4c9f49fedc053f'/>
<id>urn:sha1:af9046193148084f008501434e4c9f49fedc053f</id>
<content type='text'>
Previouly, we had errors checked in callers, which led to duplicate code
or missing checks in some places.
</content>
</entry>
<entry>
<title>py/modstruct: Remove unreachable code, and add comment about CPy diff.</title>
<updated>2016-10-07T01:54:14+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-10-07T01:54:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=dffa383b062b0dd788abed0af242b66bde910e6b'/>
<id>urn:sha1:dffa383b062b0dd788abed0af242b66bde910e6b</id>
<content type='text'>
The deleted code is unreachable because calcsize_items guarantees that
num_items corresponds to how many items there are in fmt to unpack.
</content>
</entry>
</feed>
