Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4316a7f authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "system/stack/a2dp: Prevent unsigned overflows in timestamp computation" into main

parents df094cc4 d991de24
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -631,8 +631,12 @@ static void a2dp_aac_encode_frames(uint8_t nb_frame) {
       */
      *((uint32_t*)(p_buf + 1)) = a2dp_aac_encoder_cb.timestamp;

      a2dp_aac_encoder_cb.timestamp +=
          p_buf->layer_specific * p_encoder_params->frame_length;
      // Timestamp will wrap over to 0 if stream continues on long enough
      // (>25H @ 48KHz). The parameters are promoted to 64bit to ensure that
      // no unsigned overflow is triggered as ubsan is always enabled.
      a2dp_aac_encoder_cb.timestamp =
          ((uint64_t)a2dp_aac_encoder_cb.timestamp +
           (p_buf->layer_specific * p_encoder_params->frame_length)) & UINT32_MAX;

      uint8_t done_nb_frame = remain_nb_frame - nb_frame;
      remain_nb_frame = nb_frame;
+6 −1
Original line number Diff line number Diff line
@@ -538,7 +538,12 @@ static void a2dp_sbc_encode_frames(uint8_t nb_frame) {
       */
      *((uint32_t*)(p_buf + 1)) = a2dp_sbc_encoder_cb.timestamp;

      a2dp_sbc_encoder_cb.timestamp += p_buf->layer_specific * blocm_x_subband;
      // Timestamp will wrap over to 0 if stream continues on long enough
      // (>25H @ 48KHz). The parameters are promoted to 64bit to ensure that
      // no unsigned overflow is triggered as ubsan is always enabled.
      a2dp_sbc_encoder_cb.timestamp =
          ((uint64_t)a2dp_sbc_encoder_cb.timestamp +
           (p_buf->layer_specific * blocm_x_subband)) & UINT32_MAX;

      uint8_t done_nb_frame = remain_nb_frame - nb_frame;
      remain_nb_frame = nb_frame;
+7 −1
Original line number Diff line number Diff line
@@ -353,11 +353,17 @@ void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us) {

  // Update the RTP timestamp
  *((uint32_t*)(p_buf + 1)) = a2dp_aptx_encoder_cb.timestamp;

  const uint8_t BYTES_PER_FRAME = 2;
  uint32_t rtp_timestamp =
      (pcm_bytes_encoded / a2dp_aptx_encoder_cb.feeding_params.channel_count) /
      BYTES_PER_FRAME;
  a2dp_aptx_encoder_cb.timestamp += rtp_timestamp;

  // Timestamp will wrap over to 0 if stream continues on long enough
  // (>25H @ 48KHz). The parameters are promoted to 64bit to ensure that
  // no unsigned overflow is triggered as ubsan is always enabled.
  a2dp_aptx_encoder_cb.timestamp =
      ((uint64_t)a2dp_aptx_encoder_cb.timestamp + rtp_timestamp) & UINT32_MAX;

  if (p_buf->len > 0) {
    a2dp_aptx_encoder_cb.enqueue_callback(p_buf, 1, bytes_read);
+6 −1
Original line number Diff line number Diff line
@@ -345,7 +345,12 @@ void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us) {
      (pcm_bytes_encoded /
       a2dp_aptx_hd_encoder_cb.feeding_params.channel_count) /
      BYTES_PER_FRAME;
  a2dp_aptx_hd_encoder_cb.timestamp += rtp_timestamp;

  // Timestamp will wrap over to 0 if stream continues on long enough
  // (>25H @ 48KHz). The parameters are promoted to 64bit to ensure that
  // no unsigned overflow is triggered as ubsan is always enabled.
  a2dp_aptx_hd_encoder_cb.timestamp =
      ((uint64_t)a2dp_aptx_hd_encoder_cb.timestamp + rtp_timestamp) & UINT32_MAX;

  if (p_buf->len > 0) {
    a2dp_aptx_hd_encoder_cb.enqueue_callback(p_buf, 1, bytes_read);
+6 −1
Original line number Diff line number Diff line
@@ -511,7 +511,12 @@ static void a2dp_ldac_encode_frames(uint8_t nb_frame) {
       */
      *((uint32_t*)(p_buf + 1)) = a2dp_ldac_encoder_cb.timestamp;

      a2dp_ldac_encoder_cb.timestamp += p_buf->layer_specific * ldac_frame_size;
      // Timestamp will wrap over to 0 if stream continues on long enough
      // (>25H @ 48KHz). The parameters are promoted to 64bit to ensure that
      // no unsigned overflow is triggered as ubsan is always enabled.
      a2dp_ldac_encoder_cb.timestamp =
          ((uint64_t)a2dp_ldac_encoder_cb.timestamp +
           (p_buf->layer_specific * ldac_frame_size)) & UINT32_MAX;

      uint8_t done_nb_frame = remain_nb_frame - nb_frame;
      remain_nb_frame = nb_frame;
Loading