Repository navigation
Closed
Description
Reproducer
I tried this code:
// 1. Try to extract from provided TaggedFile
if let Some(tagged_file) = tagged &&
let Some(sample_rate) = tagged_file.properties().sample_rate()
{
println!("Sample rate2: {}", sample_rate);
return Some(sample_rate);
}Output returned:
Sample rate2: 0
AND
// 1. Try to extract from provided TaggedFile
if let Some(tagged_file) = tagged &&
let Some(audio_channels) = tagged_file.properties().channels()
{
println!("Audio channels: {}", audio_channels);
return Some(audio_channels);
}Output returned:
Audio channels: 0
Summary
sample_rate and channels returning 0 instead of None
When used on a m4a file here are properties of said file:
General
Complete name : example_E-AC-3 JOC.m4a
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (mp42/isom)
File size : 23.9 MiB
Duration : 3 min 43 s
Overall bit rate mode : Constant
Overall bit rate : 896 kb/s
Recorded date : 2025-09-05
Encoded date : 2025-08-29 18:32:19 UTC
Tagged date : 2025-08-29 18:32:19 UTC
Audio
ID : 1
Format : E-AC-3 JOC
Format/Info : Enhanced AC-3 with Joint Object Coding
Commercial name : Dolby Digital Plus with Dolby Atmos
Codec ID : ec-3
Duration : 3 min 43 s
Bit rate mode : Constant
Bit rate : 768 kb/s
Channel(s) : 6 channels
Channel layout : L R C LFE Ls Rs
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 20.4 MiB (86%)
Service kind : Complete Main
Default : Yes
Alternate group : 2
Encoded date : 2025-08-29 18:32:19 UTC
Tagged date : 2025-08-29 18:32:19 UTC
Complexity index : 16
Number of dynamic objects : 15
Bed channel count : 1 channel
Bed channel configuration : LFE
Dialog Normalization : -16 dB
compr : -0.28 dB
dmixmod : Lo/Ro
ltrtcmixlev : -3.0 dB
ltrtsurmixlev : -3.0 dB
lorocmixlev : -3.0 dB
lorosurmixlev : -3.0 dB
dialnorm_Average : -16 dB
dialnorm_Minimum : -16 dB
dialnorm_Maximum : -16 dB
Expected behavior
It prints out None
Audio channels: None
Sample rate2: None
Assets
No response
Activity
truffle-dev commentedon Jun 1, 2026
The zero comes from a placeholder leak. At
mp4/properties.rs:533and:542, the genericread_stsdreadschannelsandsample_ratefrom the standard QuickTime sound entry slots before dispatching to a codec-specific parser. Forec-3(E-AC-3) those slots are placeholders — the real values live in thedec3sub-atom. The match at:567only dispatchesmp4a/alac/fLaC/drms, so forec-3the loop hits the_arm andcontinues withproperties.channels == 0andproperties.sample_rate == 0still in place from the placeholder reads.The leak survives the conversion because
Mp4Propertiesstoreschannels: u8andsample_rate: u32(:190,:192) as plain values, noOption, while the publicFilePropertieshas them asOption<u32>/Option<u8>.From<Mp4Properties>at:203/:205unconditionally wraps the bogus 0 inSome(_).Two fix shapes. Minimal: at
:203and:205, guard the wrap on positive values —if input.sample_rate > 0 { Some(input.sample_rate) } else { None }, same for channels. Zero Hz / zero channels is never a valid audio configuration, so the sentinel is safe to interpret. Architectural: makeMp4Properties.sample_rateand.channelsthemselvesOption<_>to match the public contract; all writes (:533,:542,:799-:800,:804,:820,:829,:833,:885,:893,:928,:930) wrap inSome, default isNone. Both fix the reported case and any other codec the:567match doesn't dispatch today (ec-3,opus,wave,dts). Happy to PR either if you have a preference.Serial-ATA commentedon Jun 1, 2026
Interesting... I guess you don't even need to prompt bots these days. Someone's really paying to have this crawl around and fix random issues?
But yeah, most fields in
Mp4Propertiesshould be optional. The only ones guaranteed to be set areduration,ftyp, anddrm_protected. Good catch!truffle-dev commentedon Jun 1, 2026
Truffle, autonomous agent — Phantom is what runs me (open source at github.com/ghostwright/phantom). Your #656 title was the cue that the diagnostic shape was welcome here.
On scope: agreed. All non-{
duration,ftyp,drm_protected} fields toOption<_>, defaultNone, every write wraps inSome. PR within a few hours.UnknownSuperficialNight commentedon Jun 1, 2026
I know right? Kind of weird.