Skip to content

Header.OFFSET_X cannot be negative #61

Description

@ceesb

Bug: Header.OFFSET_X cannot be negative

Header.OFFSET_X is defined as an integer offset for the X axis, but writing a
negative value raises:

OverflowError: can't convert negative int to unsigned

Minimal Reproducer

import tempfile
import trsfile
from trsfile import Header, SampleCoding

path = tempfile.NamedTemporaryFile(suffix=".trs", delete=False).name

trs = trsfile.trs_open(
    path,
    "w",
    engine="TrsEngine",
    headers={
        Header.SAMPLE_CODING: SampleCoding.SHORT,
        Header.NUMBER_SAMPLES: 8,
        Header.SCALE_X: 4e-9,
        Header.OFFSET_X: -123,
    },
)

trs.close()

Expected Behavior

The file should be created successfully and OFFSET_X should round-trip as
-123.

Actual Behavior

OverflowError: can't convert negative int to unsigned

The exception comes from trsfile/engine/trs.py:

tag_value = b'\xff' * header.length if value is None else value.to_bytes(header.length, 'little')

int.to_bytes(..., signed=False) is the default, so negative integer headers
cannot be serialized.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions