One function

TransformData in construct/construct

The author described this change as TransformData fixed, returns buildret (bug #676). It counts as a record because the check below fails on the code as it stood at cd31d6422 and passes on b0edc94ed, with nothing else changed between the two runs.

Fix saved2018-03-03
Sharing licenceMIT · LICENSE
Change size+1 1

What the code was meant to do, written into the code itself as a docstring

Parses a field on transfored data (or transforms data after building). Parsing reads a specified amount, processes data using a bytes-to-bytes decoding function, then parses subcon using those data. Building does build subcon into separate bytes, then processes using encoding encoding, then writes those data into main stream. Size is reported as `encodeamount`. Used internally to implement :class:`~construct.core.Bitwise` :class:`~construct.core.Bytewise` :class:`~construct.core.ByteSwapped` :class:`~construct.core.BitsSwapped` . Possible use-cases include encryption, obfuscation, byte-level encoding. .. warning:: Remember that subcon must consume (or produce) an amount of bytes that is same as `decodeamount` (or `encodeamount`). .. warning:: Do NOT use seeking/telling classes inside TransformData context. :param subcon: Construct instance :param decodefunc: bytes-to-bytes function, applied before parsing subcon :param decodeamount: integer, amount of bytes to read :param encodefunc: bytes-to-bytes function, applied after building subcon :param encodeamount: integer, amount of bytes to write :raises StreamError: requested reading negative amount, could not read enough bytes, requested writing different amount than actual data, or could not write all bytes :raises StreamError: subcon parsed less than `decodeamount` bytes :raises StreamError: subcon build (and encoder transformed) more or less than `encodeamount` bytes :raises StringError: building from non-bytes value, perhaps unicode Can propagate any exception from the lambdas, possibly non-ConstructError. Example::

The change

5454 if len(data) != self.encodeamount:
5555 raise StreamError("encoding transformation produced wrong amount of bytes")
5656 _write_stream(stream, data)
57- return obj
57+ return buildret
5858
5959 def _sizeof(self, context, path):
6060 return self.encodeamount

The check that tells the two apart

failpass·tests/test_core.py::test_transformdata_issue_676

Check file tests/test_core.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itcd31d6422a338fbc93d918a9578d51b29e7f3f63
Broken version dated2018-03-03
Moduleconstruct.core
Units changedTransformData
Fingerprint70c155c0f83c946e
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in construct/construct