summaryrefslogtreecommitdiff
path: root/tests/basics/struct1.py
AgeCommit message (Collapse)Author
2023-09-01py/modstruct: Support pad bytes in struct format.Daniël van de Giessen
This adds support for the x format code in struct.pack and struct.unpack. The primary use case for this is ignoring bytes while unpacking. When interfacing with existing systems, it may often happen that you either have fields in a struct that aren't properly specified or you simply don't care about them. Being able to easily skip them is useful. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
2023-06-08tests: Replace umodule with module everywhere.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-27all: Fix spelling mistakes based on codespell check.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2017-09-01py/modstruct: Check and prevent buffer-write overflow in struct packing.Damien George
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.
2017-09-01py/modstruct: Check and prevent buffer-read overflow in struct unpackingDamien George
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.
2017-06-10tests/basics: Convert "sys.exit()" to "raise SystemExit".Paul Sokolovsky
2017-03-04tests/basic: Split tests into working with small ints and not working.Paul Sokolovsky
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.
2016-12-28tests/basics: Add tests to improve coverage of binary.c.Rami Ali
2016-12-19tests/struct*: Make skippable.Paul Sokolovsky
2016-10-07tests: Improve coverage of struct with test for non-compliant behaviour.Damien George
2016-09-19tests/struct1: Test "l" specifier to improve coverage.Paul Sokolovsky
2016-05-14tests/struct1: Add testcase for an unknown type char.Paul Sokolovsky
2016-01-19py: Add ustruct.pack_into and unpack_fromDave Hylands
2015-10-31tests/base/struct1.py: Add test for repetition counters.Paul Sokolovsky
2015-10-01tests: Add further tests for mpz code.Damien George
2015-09-03tests: Add tests to improve coverage of objstr.c.Damien George
2015-05-04modstruct: Rename module to "ustruct", to allow full Python-level impl.Paul Sokolovsky
2015-04-25py: Support conversion of bignum to bytes.Damien George
This gets int.to_bytes working for bignum, and also struct.pack with 'q' and 'Q' args on 32-bit machines. Addresses issue #1155.
2015-04-05tests: Add some more tests to improve code coverage of corner cases.Damien George
2014-12-05py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.Damien George
mp_obj_int_get_truncated is used as a "fast path" int accessor that doesn't check for overflow and returns the int truncated to the machine word size, ie mp_int_t. Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word sized values. Addresses issues #779 and #998.
2014-06-25modstruct: Fix alignment handling issues.Paul Sokolovsky
Also, factor out mp_binary_get_int() function.
2014-05-12modstruct: Implement count specifier for strings (e.g. "100s").Paul Sokolovsky
Infra for counts of other types is there, need last mile to be implemented.
2014-04-19modstruct: Initial implementation of struct.pack().Paul Sokolovsky
2014-04-11modstruct: Basic implementation of native struct alignment and types.Paul Sokolovsky
2014-04-11modstruct: Refactor to support both LE and BE packed structs.Paul Sokolovsky
2014-04-10py: Start implementing "struct" module.Paul Sokolovsky
Only calcsize() and unpack() functions provided so far, for little-endian byte order. Format strings don't support repition spec (like "2b3i"). Unfortunately, dealing with all the various binary type sizes and alignments will lead to quite a bloated "binary" helper functions - if optimizing for speed. Need to think if using dynamic parametrized algos makes more sense.