sensemakersamsterdam / OpenEars

sensor to classify sounds
GNU General Public License v3.0
5 stars 6 forks source link

Buffer overflow #8

Closed hugokoopmans closed 4 years ago

hugokoopmans commented 4 years ago

Ik wil de recording window precies 10 seconden hebben dus zou

python3 capture.py --min_time 10.0 --max_time 10.0 -s ./samples

moeten werken, helaas krijg ik

[INFO] 2020-06-23 09:03:48,114: Buffer overflow, truncate 513.0b. Exception in thread captor: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/pi/OpenEars/devicehive-dev/audio/captor.py", line 107, in _capture capture_buf = capture_buf[overflow:] TypeError: slice indices must be integers or None or have an index method

gmos commented 4 years ago

When min_time and max_time are equal you almost always overshoot the buffer with a small bit due to the read size. In captor they then want to truncate the beginning of the buffer to get it exactly on max_size. Unfortunately they use a real as index into the buffer for the slicing operation, causing the trap. Cast to int added before the slicing.

gmos commented 4 years ago

Solved in 0c19fdfa194e31f73a58462087a34e99a53991fd