hifiberry / hifiberry-dsp

DSP toolkit
MIT License
143 stars 36 forks source link

DSPToolkit.set_filters off by one overwrites memory #8

Closed jlindblad closed 5 years ago

jlindblad commented 5 years ago

DSPToolkit.clear_iir_filters() calls DSPToolkit.set_filters() with cutoff_long=True. I have a custom profile with only six filters, so length is 30 which means maxlen is 6. But the loop writing the data to memory will loop 7 times, causing data corruption:

        i = 0
        for f in filters:
            logging.debug(f)
            if mode == MODE_LEFT or mode == MODE_BOTH:
                if i < length_left:
                    self.sigmatcp.write_biquad(addr_left + i * 5, f)
            if mode == MODE_RIGHT or mode == MODE_BOTH:
                if i < length_right:
                    self.sigmatcp.write_biquad(addr_right + i * 5, f)
            i += 1
            if i > maxlen:
                break

Changing if i > maxlen to if i >= maxlen fixes the problem.

hifiberry commented 5 years ago

Thanks for reporting this. I just fixed this in the master branch.

hifiberry commented 5 years ago

New release 0.18 with this bugfix included has been uploaded to pypi.