bluez5: fix ISO sequence numbering

Pass zero-length packets to the codec. BAP/ISO may use these to indicate
missing data.

Fix A2DP codecs to not parse input with spa_return_val_if_fail, that's
meant for assertions. Just return -EINVAL directly, it's normal that
input data may contain garbage.
This commit is contained in:
Pauli Virtanen 2025-06-27 21:30:55 +03:00 committed by Wim Taymans
parent 02d5d9bc1f
commit ff81fc9f7b
10 changed files with 31 additions and 11 deletions

View file

@ -581,7 +581,8 @@ static int codec_start_decode (void *data,
const struct rtp_header *header = src; const struct rtp_header *header = src;
size_t header_size = sizeof(struct rtp_header); size_t header_size = sizeof(struct rtp_header);
spa_return_val_if_fail (src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -426,7 +426,8 @@ static int codec_start_decode (void *data,
const struct rtp_header *header = src; const struct rtp_header *header = src;
size_t header_size = sizeof(struct rtp_header); size_t header_size = sizeof(struct rtp_header);
spa_return_val_if_fail(src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -301,6 +301,9 @@ static int codec_encode(void *data,
static SPA_UNUSED int codec_start_decode (void *data, static SPA_UNUSED int codec_start_decode (void *data,
const void *src, size_t src_size, uint16_t *seqnum, uint32_t *timestamp) const void *src, size_t src_size, uint16_t *seqnum, uint32_t *timestamp)
{ {
if (!src_size)
return -EINVAL;
return 0; return 0;
} }

View file

@ -637,7 +637,8 @@ static SPA_UNUSED int codec_start_decode (void *data,
const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), void); const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), void);
size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload); size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
spa_return_val_if_fail (src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -667,7 +667,8 @@ static int codec_start_decode (void *data,
const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), struct rtp_payload); const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), struct rtp_payload);
size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload); size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
spa_return_val_if_fail (src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -444,7 +444,8 @@ static int codec_start_decode (void *data,
const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), void); const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), void);
size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload); size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
spa_return_val_if_fail (src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -1188,7 +1188,8 @@ static SPA_UNUSED int codec_start_decode (void *data,
const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), void); const struct rtp_payload *payload = SPA_PTROFF(src, sizeof(struct rtp_header), void);
size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload); size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
spa_return_val_if_fail (src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -599,7 +599,8 @@ static int codec_start_decode (void *data,
const struct rtp_header *header = src; const struct rtp_header *header = src;
size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload); size_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
spa_return_val_if_fail (src_size > header_size, -EINVAL); if (src_size <= header_size)
return -EINVAL;
if (seqnum) if (seqnum)
*seqnum = ntohs(header->sequence_number); *seqnum = ntohs(header->sequence_number);

View file

@ -37,6 +37,8 @@ struct impl {
int framelen; int framelen;
int samples; int samples;
unsigned int codesize; unsigned int codesize;
uint16_t seqnum;
}; };
struct settings { struct settings {
@ -1274,13 +1276,23 @@ static int codec_encode(void *data,
return processed; return processed;
} }
static SPA_UNUSED int codec_start_decode (void *data, static int codec_start_decode (void *data,
const void *src, size_t src_size, uint16_t *seqnum, uint32_t *timestamp) const void *src, size_t src_size, uint16_t *seqnum, uint32_t *timestamp)
{ {
struct impl *this = data;
/* packets come from controller, so also invalid ones bump seqnum */
this->seqnum++;
if (!src_size)
return -EINVAL;
if (*seqnum)
*seqnum = this->seqnum;
return 0; return 0;
} }
static SPA_UNUSED int codec_decode(void *data, static int codec_decode(void *data,
const void *src, size_t src_size, const void *src, size_t src_size,
void *dst, size_t dst_size, void *dst, size_t dst_size,
size_t *dst_out) size_t *dst_out)

View file

@ -637,8 +637,6 @@ static void media_on_ready_read(struct spa_source *source)
/* read */ /* read */
size_read = read_data (this, &now); size_read = read_data (this, &now);
if (size_read == 0)
return;
if (size_read < 0) { if (size_read < 0) {
spa_log_error(this->log, "failed to read data: %s", spa_strerror(size_read)); spa_log_error(this->log, "failed to read data: %s", spa_strerror(size_read));
goto stop; goto stop;