MIT-LCP / MIT-LCP/wfdb-python

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

Open
#515 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
853
Forks
322
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with calc_adc_params as called by wfdb.wrsamp, using the attached data.float32 file and the reproduction snippet to trigger the failure. Inspect how chmin and chmax are derived for fmt 32 and compare them with the allowed range. Done means the reproduction completes without an IndexError while values remain within the format limits.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.