implement LHVCDecoderConfigurationBox (lhvC)#141
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughAdds full support for the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/moov/trak/mdia/minf/stbl/stsd/hevc/lhvc.rs (1)
32-32: Capnaluspre-allocation for untrusted input.
num_nalusis read directly from the buffer and used asVec::with_capacity(num_nalus as usize). While bounded tou16::MAX, consider capping it for consistency with the arrays allocation on line 28 (which uses.min(8)). The same pattern is used inhvcc.rsline 75 (also uncapped there), but the learning recommends capping.Suggested fix
- let mut nalus = Vec::with_capacity(num_nalus as usize); + let mut nalus = Vec::with_capacity(num_nalus.min(16) as usize);Based on learnings: "when decoding arrays from untrusted input, use
Vec::with_capacity(std::cmp::min(count, N))to cap initial memory allocation to a reasonable value."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/moov/trak/mdia/minf/stbl/stsd/hevc/lhvc.rs` at line 32, The allocation for nalus uses Vec::with_capacity(num_nalus as usize) which can grow from untrusted input; change the allocation to cap the initial capacity (mirror the .min(8) behavior used above) by using std::cmp::min on num_nalus (e.g., min(num_nalus as usize, 8)) so nalus is pre-allocated with a bounded size; update the allocation site where nalus is created in lhvc.rs accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/moov/trak/mdia/minf/stbl/stsd/hevc/lhvc.rs`:
- Around line 77-81: The encode path (encode_body) writes temporal_id_nested
into bit 3, colliding with num_temporal_layers; change the shift for
temporal_id_nested from 1 << 3 to 1 << 2 so it matches how decode_body reads
`(temp & 0b0000_0100) != 0` and mirrors hvcc.rs's `<< 2` behavior; update the
bit composition in the encode expression that currently builds ((0b11 << 6) |
(self.num_temporal_layers << 3) | (if self.temporal_id_nested { 1 << 3 } else {
0 }) | self.length_size_minus_one).encode(buf)? to use `1 << 2` for
temporal_id_nested, and add a round-trip unit test exercising encode/decode with
temporal_id_nested = true and a non-zero num_temporal_layers to prevent
regressions.
---
Nitpick comments:
In `@src/moov/trak/mdia/minf/stbl/stsd/hevc/lhvc.rs`:
- Line 32: The allocation for nalus uses Vec::with_capacity(num_nalus as usize)
which can grow from untrusted input; change the allocation to cap the initial
capacity (mirror the .min(8) behavior used above) by using std::cmp::min on
num_nalus (e.g., min(num_nalus as usize, 8)) so nalus is pre-allocated with a
bounded size; update the allocation site where nalus is created in lhvc.rs
accordingly.
c19a679 to
3fd319c
Compare
See ISO/IEC 14496-15:2024 Section 9 Resolves kixelated#126
3fd319c to
3a87260
Compare
See ISO/IEC 14496-15:2024 Section 9
Resolves #126