<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/tests/basics/struct1.py, branch 6.0.x</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.0.x</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.0.x'/>
<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>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>tests/basics: Convert "sys.exit()" to "raise SystemExit".</title>
<updated>2017-06-10T17:03:01+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2017-06-10T17:03:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=a2803b74f48849cb3a11fb492fee891044ecc1f4'/>
<id>urn:sha1:a2803b74f48849cb3a11fb492fee891044ecc1f4</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests/basic: Split tests into working with small ints and not working.</title>
<updated>2017-03-03T21:13:27+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2017-03-03T21:13:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=3ab6aa3a6d0506e805caa19369bef279c1c789b4'/>
<id>urn:sha1:3ab6aa3a6d0506e805caa19369bef279c1c789b4</id>
<content type='text'>
Tests which don't work with small ints are suffixed with _intbig.py. Some
of these may still work with long long ints and need to be reclassified
later.
</content>
</entry>
<entry>
<title>tests/basics: Add tests to improve coverage of binary.c.</title>
<updated>2016-12-28T05:11:54+00:00</updated>
<author>
<name>Rami Ali</name>
<email>flowergrass@users.noreply.github.com</email>
</author>
<published>2016-12-28T04:29:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=65574f817a949fea2316c335da866c1b8d20f1fb'/>
<id>urn:sha1:65574f817a949fea2316c335da866c1b8d20f1fb</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests/struct*: Make skippable.</title>
<updated>2016-12-19T16:41:12+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2016-12-19T16:40:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=91359c86900ea664a8ad4fefad22b630bd714e2d'/>
<id>urn:sha1:91359c86900ea664a8ad4fefad22b630bd714e2d</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests: Improve coverage of struct with test for non-compliant behaviour.</title>
<updated>2016-10-07T01:57:25+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-10-07T01:57:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=82af4d6749072d01195da647f54b79c80f1ad731'/>
<id>urn:sha1:82af4d6749072d01195da647f54b79c80f1ad731</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests/struct1: Test "l" specifier to improve coverage.</title>
<updated>2016-09-19T14:01:02+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2016-09-19T13:59:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=b85bcd671c5dced62fa00f2e3c0c5541b0d16593'/>
<id>urn:sha1:b85bcd671c5dced62fa00f2e3c0c5541b0d16593</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests/struct1: Add testcase for an unknown type char.</title>
<updated>2016-05-14T12:54:09+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2016-05-14T12:54:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=719f8c044a9d30a8d9f4356af1310f18e82e5b67'/>
<id>urn:sha1:719f8c044a9d30a8d9f4356af1310f18e82e5b67</id>
<content type='text'>
</content>
</entry>
</feed>
