From f8abfc46ca564bc58c2bb6bbec4fb4057cc77174 Mon Sep 17 00:00:00 2001 From: "Kamal S. Fuseini" Date: Sat, 9 Nov 2024 00:55:34 +0000 Subject: [PATCH 1/3] Check not in FU before calling finalize and check pieces bounds before indexing --- src/codec/h265.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/codec/h265.rs b/src/codec/h265.rs index 22edc23..4b5b2c6 100644 --- a/src/codec/h265.rs +++ b/src/codec/h265.rs @@ -3,6 +3,7 @@ use std::convert::TryFrom; use std::fmt::Write; +use base64::Engine; use bytes::{Buf, BufMut, Bytes, BytesMut}; use hevc_parser::hevc::{NalHeader, UnitType}; use log::{debug, log_enabled, trace}; @@ -167,7 +168,7 @@ impl Depacketizer { .last() .ok_or("nals should not be empty".to_string())? .hdr; - if can_end_au(last_nal_hdr.nal_unit_type()) { + if !access_unit.in_fu && can_end_au(last_nal_hdr.nal_unit_type()) { access_unit.end_ctx = *pkt.ctx(); self.pending = Some(self.finalize_access_unit(access_unit, "ts change")?); @@ -436,6 +437,9 @@ impl Depacketizer { } for nal in &self.nals { let next_piece_idx = usize::try_from(nal.next_piece_idx).expect("u32 fits in usize"); + if next_piece_idx > self.pieces.len() { + return Err("Incomplete buffered nals finalizing access unit".into()); + } let nal_pieces = &self.pieces[piece_idx..next_piece_idx]; match nal.hdr.nal_unit_type() { UnitType::NalVps => { @@ -620,9 +624,11 @@ impl InternalParameters { if !matches!(key, "sprop-sps" | "sprop-pps" | "sprop-vps") { continue; } - let nal = base64::decode(value).map_err(|_| { - "bad parameter: NAL has invalid base64 encoding".to_string() - })?; + let nal = base64::engine::general_purpose::STANDARD + .decode(value) + .map_err(|_| { + "bad parameter: NAL has invalid base64 encoding".to_string() + })?; if nal.is_empty() { return Err(format!("bad parameter {key}: empty NAL")); } From 04a940b4590ef308690057c2bea130ca90d06cb4 Mon Sep 17 00:00:00 2001 From: "Kamal S. Fuseini" Date: Sat, 9 Nov 2024 01:15:08 +0000 Subject: [PATCH 2/3] Add license header to h265 codec file --- src/codec/h265.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/codec/h265.rs b/src/codec/h265.rs index 4b5b2c6..08d0ed1 100644 --- a/src/codec/h265.rs +++ b/src/codec/h265.rs @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + //! [H.265]-encoded video. use std::convert::TryFrom; From 651a1f964cab7ab8797e258c52d01f87c6bdf088 Mon Sep 17 00:00:00 2001 From: "Kamal S. Fuseini" Date: Sat, 9 Nov 2024 01:17:17 +0000 Subject: [PATCH 3/3] Add copyright header to h265 code file --- src/codec/h265.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codec/h265.rs b/src/codec/h265.rs index 08d0ed1..73903d6 100644 --- a/src/codec/h265.rs +++ b/src/codec/h265.rs @@ -1,3 +1,4 @@ +// Copyright (C) 2021 Scott Lamb // SPDX-License-Identifier: MIT OR Apache-2.0 //! [H.265]-encoded video.