Skip to content

calc_adc_params can produce off-by-one problems, crashing wrsamp #515

Open
@Ivorforce

Description

@Ivorforce

I have some data that crashes wrsamp because calc_adc_params produces values that don't fit the data (off by one):

chmin = -2147483648
chmax = 2147483648
IndexError: Channel 0 contain values outside allowed range [-2147483648, 2147483647] for fmt 32

As you can see, chmax is just above the dmax of 2147483647 for 32.

This is some data for reproduction:
data.float32.zip

You can try it with:

data = np.reshape(np.fromfile("data.float32", dtype=np.float32), [-1, 12])
wfdb.wrsamp(
    record_name="test",
    sig_name=[f"d{x}" for x in range(12)],
    units=["mv"] * 12,
    fs=500,
#    fmt=["16"] * 12,
    p_signal=data
)

Note how passing fmt=16 fixes the problem in this particular case, probably by chance because it happens to not trigger the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions