Freescale / libimxvpuapi

i.MX VPU API Library
GNU Lesser General Public License v2.1
88 stars 54 forks source link

imx8m-hantro: Reset decoder write_offset to fill_level when moving read_offset. #51

Closed dougnazar closed 2 years ago

dougnazar commented 2 years ago

With the right timing, it's possible to have the read side all caught up and the write side at the end of the buffer. This will cause the memmove() to move 0 bytes and the write offset to be reduced by 0, leading to a SIGSEGV in the memcpy() as we try to write after the buffer.

Signed-off-by: Doug Nazar nazard@nazar.ca

dougnazar commented 2 years ago

At the time of the crash, the relevant fields were:

data_size               = 4056

decoder->stream_buffer_read_offset  = 0
decoder->stream_buffer_write_offset = 16777216
decoder->stream_buffer_fill_level   = 0
decoder->stream_buffer_size     = 16777216

Can take between a couple days & a couple weeks to show up.

dougnazar commented 2 years ago

I also didn't see anything synchronizing access to those fields. Did I miss something?

dv1 commented 2 years ago

Good catch, thanks. As for synchronization, do you mean thread sync? The API is not designed to be thread safe.