Message313098
The frequency rate is saved as a 80-bit floating point value in AIFC files. There are issues with reading large values.
1. Values with maximal exponent are read as aifc._HUGE_VAL which is less then sys.float_info.max. Thus greater values can be read as lesser values.
>>> aifc._read_float(io.BytesIO(b'\x7f\xff\xff\xff\xff\xff\xff\xff\xf8\x00'))
1.79769313486231e+308
>>> aifc._read_float(io.BytesIO(b'\x43\xfe\xff\xff\xff\xff\xff\xff\xf8\x00'))
1.7976931348623157e+308
>>> aifc._read_float(io.BytesIO(b'\x43\xfe\xff\xff\xff\xff\xff\xff\xff\xff'))
inf
2. If exponent is not maximal, but large enough, this cause an OverflowError. It would be better consistently return the maximal value or inf.
>>> aifc._read_float(io.BytesIO(b'\x44\xfe\xff\xff\xff\xff\xff\xff\xf8\x00'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython3.7/Lib/aifc.py", line 198, in _read_float
f = (himant * 0x100000000 + lomant) * pow(2.0, expon - 63)
OverflowError: (34, 'Numerical result out of range')
OverflowError when read a broken aifc file can be unexpected.
The proposed PR tries to make reading floats more consistent. I'm not sure it is correct. |
|
Date |
User |
Action |
Args |
2018-03-01 16:50:35 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, tim.peters, mark.dickinson |
2018-03-01 16:50:35 | serhiy.storchaka | set | messageid: <1519923035.62.0.467229070634.issue32978@psf.upfronthosting.co.za> |
2018-03-01 16:50:35 | serhiy.storchaka | link | issue32978 messages |
2018-03-01 16:50:35 | serhiy.storchaka | create | |
|