MIT-LCP / wfdb-python

Native Python WFDB package
MIT License
730 stars 298 forks source link

Broken with libFLAC < 1.4.0 ("internal psf_fseek() failed") #486

Open bemoody opened 2 months ago

bemoody commented 2 months ago

Some versions of the SoundFile package on PyPI, including the latest version (0.12.1), appear to be broken. It appears that something is wrong with the precompiled "libsndfile_x86_64.so". I have no idea about other platforms. I don't know if this is actually a bug in libFLAC, or in libsndfile, or in SoundFile, or a bug in how libFLAC/libsndfile was compiled.

The latest version in the libsndfile-binaries repo is possibly fixed, but there hasn't been a new release of SoundFile for a while.

Here is an example file, gzipped and base64ed:

H4sIAAAAAAACA0vzSXRmYGBQEmAQAFKCDGzi4gUsHxiY/BiUfKRUi1hP7hBiWKmeMlUwt4WBQUMB
qKYoNS21KDUvOVUhJzPJzcfRWcFQz1jPWMHIwNDSwMLABKiE4f+P0xoMb4UZmFns/6OC+f9HFnj4
f2SDf2oMbBz1aIL2IywQDo/wRPDHh4FHAD1h1I+wQGgf4YngR/0yULXA+IoBBnhVQQJMj+ECQdEg
AeYncIHnRSABlo9wgTfLQQKs3+ACkX0gAbb/cAG2DyAB9h9wgc03QQIcV+ECglEgAc5LcIElxSAB
rttwgd+8IAHuO3ABPxWQAM9JuIDrR5AA7zm4wIcbIAG+43CB9WDf8h+AC0j1gwQE5sIFspaCBARn
wQXu94AEhCbDBRo+gQSEp8AFTG+DBEQa4QJ2fCAB0Ta4QLc6SECsHy5wJRIkIN4BF0gsAAlILIUL
HP4MEpBcBBcouwUSkFoNF9BcAhKQXgMXmNMLEpDZCReYHgESkN0HF1AqBAnIbYcL1PKDBOQ3wAVO
qIEEFHjhAnPBsa/IBRfQAMe+EjNcoJwHJKDMAhc4BExB1RoqvP9nMjMwMYwCfIBxsLcU2BhYRmMJ
L2Ae7PU8DwPHaCzhBeyDvZY+wAsARLgU7hMOAAA=

I think this is a valid FLAC file, though I'm not sure. Running python3 -c 'import soundfile; soundfile.SoundFile("example.dat").read(78419)' should succeed.

tompollard commented 1 week ago

Okay, sorry, got it. I'm now first doing this:

base64 -d -i example.txt -o example.zip
gzip -dc example.zip > example.dat

On MacOS 14.6 Beta (23G5061b) M1 Max, I see the error for soundfile==0.11.0 but not for 0.12.1

soundfile==0.11.0

pip install soundfile==0.11.0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/tompollard/projects/wfdb-python/env/lib/python3.9/site-packages/soundfile.py", line 892, in read
    frames = self._array_io('read', out, frames)
  File "/Users/tompollard/projects/wfdb-python/env/lib/python3.9/site-packages/soundfile.py", line 1341, in _array_io
    return self._cdata_io(action, cdata, ctype, frames)
  File "/Users/tompollard/projects/wfdb-python/env/lib/python3.9/site-packages/soundfile.py", line 1353, in _cdata_io
    self.seek(curr + frames, SEEK_SET)  # Update read & write position
  File "/Users/tompollard/projects/wfdb-python/env/lib/python3.9/site-packages/soundfile.py", line 799, in seek
    _error_check(self._errorcode)
  File "/Users/tompollard/projects/wfdb-python/env/lib/python3.9/site-packages/soundfile.py", line 1404, in _error_check
    raise LibsndfileError(err, prefix=prefix)
soundfile.LibsndfileError: Internal psf_fseek() failed.

soundfile==0.12.1

pip install soundfile==0.12.1

Runs without error.

bemoody commented 1 week ago

Thanks. That's what I expected. The soundfile builds using libFLAC 1.3.3 apppear to be affected by #486 but not #488; the soundfile builds using libFLAC 1.4.2 appear to be affected by #488 but not #486.

bemoody commented 1 week ago

After hammering on this a bit more, it looks like this is actually a bug in libFLAC, and not a bug in libsndfile.

For example, running flac -df -o /dev/null bug486.dat --skip=78420 fails.

However, this bug is not detected by the prober I posted in #488. And as we've seen, this bug exists in libFLAC 1.3.3 but not 1.4.2, whereas the other bug exists in 1.4.2 but not 1.3.3.

bemoody commented 1 week ago

1.2.0 broken ... 1.3.3 broken 1.3.4 broken

fixed by 3fc5ba46375e48009cd9428091cd2ffd242de6b9

1.4.0 working 1.4.1 working 1.4.2 working 1.4.3 working