pod: only call the overflow callback when still needed

When we are already past the size of the buffer, don't bother calling
the overflow callback anymore, the buffer is already corrupted.

Otherwise it would be possible to have the overflow callback fail the
first time around, some data will be skipped, and then the next
overflow callback would succeed, giving the impression that all is
fine.

Add a unit test for this.
This commit is contained in:
Wim Taymans 2022-09-20 16:59:25 +02:00
parent c9753b0722
commit 7bf84fa5e2
2 changed files with 53 additions and 2 deletions

View file

@ -143,8 +143,10 @@ static inline int spa_pod_builder_raw(struct spa_pod_builder *builder, const voi
if (offset + size > builder->size) {
res = -ENOSPC;
spa_callbacks_call_res(&builder->callbacks, struct spa_pod_builder_callbacks, res,
overflow, 0, offset + size);
if (offset <= builder->size)
spa_callbacks_call_res(&builder->callbacks,
struct spa_pod_builder_callbacks, res,
overflow, 0, offset + size);
}
if (res == 0 && data)
memcpy(SPA_PTROFF(builder->data, offset, void), data, size);