You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MP4: a write error panics in AtomWriterCompanion::drop instead of returning Err #738
impl Drop for AtomWriterCompanion (lofty/src/mp4/write.rs) asserts:
assert!(self.finished || std::thread::panicking(),"`AtomWriterCompanion` was not finished");
In lofty/src/mp4/ilst/write.rs, write_to calls atom_writer.start_write() and then runs several fallible steps with ? before reaching write_handle.finish(). Examples are the seek, build_ilst(...).map_err(TagEncodingError::from)? and the atom_tree / nested_atom lookups mapped through handle_atom_parse_error. When any of them returns Err, the companion is dropped unfinished. The Drop impl then panics instead of returning the error to the caller of save_to / save_to_path.
With panic = "unwind", a recoverable LoftyError becomes a panic.
With panic = "abort", which many desktop applications use, writing a tag to a malformed or unusual MP4 aborts the whole process.
Expected
The write returns the Err. Possible fixes:
make the check a debug_assert!, or
make Drop a no-op and let finish() be the only commit point (the companion's buffered contents are simply discarded on an early return).
Context
We currently work around this downstream by pre-validating MP4 files before every tag write, which duplicates parsing that lofty already does.
Related
A second MP4 write issue that we also hit, atom_tree returning index 0 when no ilst exists (so a meta with hdlr and no ilst loses its hdlr on write), is already listed as item 023 in #703 and is still present on main. +1 for that one as well.
Activity