Repository navigation
fix: Stop the remaining readers from dropping or inventing a value - #186
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #186 +/- ##
==========================================
+ Coverage 93.27% 93.65% +0.38%
==========================================
Files 558 590 +32
Lines 109406 112493 +3087
Branches 14187 14799 +612
==========================================
+ Hits 102045 105358 +3313
+ Misses 4396 4221 -175
+ Partials 2965 2914 -51 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ID3v2 text lists were split on NUL and on '/', so a single name such as AC/DC read as two performers, AC and DC, where ffprobe, exiftool and MediaInfo read one. ID3v2.4 text frames separate values with NUL (id3v2.4.0-structure §4); ID3v2.3's TPE1 note about '/' is not applied, in any version. Performers, AlbumArtists, Composers, Genres and GetTextFrameValues now split on NUL only. "(17)" in TCON is still the ID3v1 genre Rock, and track and disc numbers keep their n/m form. Vorbis comments already repeat the field; a pin shows a slash stays inside one value there too. The README, ROADMAP and docs describe the ID3 versions: ID3v1 and v1.1, ID3v2.2 (read, with 3-character IDs mapped), and ID3v2.3 and v2.4 read and written, a new tag being v2.4.
A tag read as ID3v2.2 kept major version 2, and the render wrote 4-character v2.3 frame headers under that v2.2 header, so no reader could parse a saved file and a save with no edits lost every field. A v2.2 tag is now written as ID3v2.3. Every v2.2 frame has a v2.3 frame with the same body (ID3v2.2 §4, ID3v2.3 §4), and v2.2's text encodings are v2.3's, while ID3v2.4 removed TYER, TDAT, TIME, TRDA, TORY, TSIZ, IPLS, RVAD and EQUA. The v2.2 ID table now covers the whole frame list, plus Apple's TCP, TS2, TSA, TSC, TSP and TST, which exiftool and mutagen read the same way. A frame with no v2.3 ID is stepped over by its size instead of ending the walk. A PIC frame's 3-character image format is read as a MIME type; a PIC that holds the APIC layout keeps the MIME type it was read with. Version still reports 2 for the tag that was read. The GetTextFrameValues docs now cite the NUL rule for v2.2, v2.3 and v2.4.
…e title (#188) Matroska Album read only TITLE at target 50, so the untargeted ALBUM tag ffmpeg writes read as null, and setting the album added a TITLE to the untargeted Tag. ffprobe then showed the album as the file title, replacing the segment title, and this library read it back as the title. Album now reads TITLE at target 50, then ffmpeg's ALBUM, then a TITLE in a Tag with no TargetTypeValue. A set goes in an ALBUM tag at target 50 (ffmpeg's untargeted Tag, or a new target-50 Tag), which ffprobe, MediaInfo and ExifTool report as the album, unless the file already has an explicit target-50 TITLE. That TITLE is updated, with any ALBUM beside it. A target-50 TITLE is also the track's title while no narrower TITLE exists, so before it changes or is cleared the title shown is kept at target 30, in a Tag after the album's: ffprobe and MediaInfo show the TITLE of the last Tag that has one. A clear removes every album source after keeping the title the same way. Title reads ffmpeg's untargeted TITLE before an explicit album TITLE at 50, and the album TITLE read and written is the default-language one. The album artist had the same shape: on an ffmpeg file, setting AlbumArtists wrote an untargeted ARTIST that every reader shows as the artist. Album artists that would change the track's artist are written as ALBUM_ARTIST there, and a clear keeps the artist at target 30.
An MP4 or QuickTime video sample entry was parsed as an audio one, so a 320-pixel-wide video reported a 320 Hz sample rate, and IMediaFile.VideoProperties was always null. The track is now chosen by its handler ("vide" or "soun", ISO/IEC 14496-12) or, when the handler is missing or another, by its sample entry, and a track another track names in tref/chap (Apple's chapter images) is not the movie's video.
Mp4File.VideoProperties (VideoProperties?) gives the first video track's width, height, codec and duration, and MediaTypes includes Video. Width and height are the sample entry's coded size, as ffprobe and MediaInfo report it. VideoProperties.Rotation is the clockwise rotation the tkhd matrix asks for, 0 to 359 degrees, and 0 for a matrix that mirrors or skews the picture. The codec is named from the fourcc (H.264, HEVC, VP9, AV1) and, for mp4v, from the esds objectTypeIndication; an esds whose ES_Descriptor sets the stream-dependence, URL or OCR flag is read, where the AAC bitrate of such a file was 0.
The choice of track is pinned on every entry point, on hostile input and at scale; the esds, short tkhd and skewed-matrix edges are pinned too. The MP4 tests live in the MP4 folder and build tracks with a shared builder.
VideoProperties.Rotation is the rotation the file asks a player to apply. Matroska stores it in the track's Video/Projection: for a rectangular projection (ProjectionType 0) with no yaw or pitch, ProjectionPoseRoll rotates the image for presentation, counter-clockwise (RFC 9559 §5.1.4.1.28.46), and is reported as the clockwise rotation. Any other projection, a pose with yaw or pitch, or a roll out of range reports 0, as do the formats without a rotation field. The yaw edge is pinned.
A picture whose role was not front cover came back as a front cover after a save. MP4 covr has no role field: the data type is the image format. A role other than front cover is now kept by a private convention, the role one higher than the ID3 picture type in the top byte of the data atom's locale, a country byte no real locale uses; a locale of 0, or any real one, reads as front cover, and AVFoundation, QuickLook, ffprobe, ExifTool and MediaInfo still show the image as a cover. Mp4Picture.PictureType returns that role instead of always FrontCover.
APE wrote Other and every role without its own key as 'Cover Art (Front)'. GetKey and GetKeyForPictureType now return 'Cover Art (<role name>)', and LeadArtist has its own 'Cover Art (LeadArtist)' key, where it was written under Artist. The key reader passed the text in the parentheses to Enum.TryParse, which also accepts numbers and comma lists, so 'Cover Art (3)' read as a front cover and 'Cover Art (Other, BackCover)' as a back cover. Only a role's name is read now, in any case and with a space between its words ('Lead Artist'); anything else is Other. The check that a role read from a file is defined is shared with MP4 (PictureTypes.IsDefined), and builds on netstandard2.0 and 2.1.
…alue is set IMediaFile.Tag was null on a file with no tag, so file.Tag!.Title = x threw, and the stored-tag properties were the only way to tag such a file. A tagless MP3, raw AAC, DSF, DFF, MPEG-PS, AIFF, WAV, FLAC, WavPack, Monkey's Audio, Musepack or MP4 file now has a view. Reading it creates nothing; the first write creates the format's tag (ID3v2 in MP3, AAC, DSF, DFF, MPEG-PS, WAV and AIFF, a Vorbis comment in FLAC, APEv2 in WavPack, Monkey's Audio and Musepack, an ilst in MP4). WAV gets ID3v2 rather than RIFF INFO, which holds one Latin-1 value per field. MediaFileResult.Tag reads the file's own Tag, so the two cannot differ. Every view of a file shares one TagCreation. A write that leaves the tag it created storing nothing (custom fields and pictures included, Tag.StoresNothing) drops it again, a clear never creates one, and every public Render and save first settles the creation, so a created tag emptied through the stored-tag property (Id3v2Tag, ApeTag, VorbisComment, Mp4File.Tag) is not written either. An empty view reports no tag type, AIFF's view no longer leaves an empty ID3 tag, and the view reports the custom fields the tag it would create takes (CreatesCustomFields). A property test runs every format, Ogg Vorbis, Opus, Ogg FLAC, ASF, AVI, Matroska and Audible included, on every entry point and save: an edit that leaves no value saves what a save with no edit saves, and a title and two performers read back. Tests that checked Tag for null check that the view is empty and of no tag type and that every stored-tag property is null (TaglessFixtures.AssertStoresNoTag). The README and the IMediaFile.Tag docs describe the view and that an emptied view writes nothing. Breaking: code that tests file.Tag is null to mean "no tag" must test Tag.IsEmpty or the stored-tag properties.
…itle Setting a JPEG Tag.Title changed nothing. The title is now read with an XML reader from XMP dc:title, or from IFD0 XPTitle (0x9C9B) when the XMP has none. A set writes one x-default dc:title, in the XMP packet every reader reads (a new XMP segment after the JFIF and Exif segments when the file has none, with the dc namespace declared), and a set or a clear also removes every XPTitle through the plain-structure Exif field edit, so ExifTool, Exiv2, macOS ImageIO and TagLib# show the new title (measured); Windows reads dc:title when no XPTitle is there. A packet whose JPEG signature has a space before the NUL is updated as a copy, and a packet with no rdf:Description gets one. A title whose XMP would not fit in one 64 KB segment is refused with its own reason, and an edit refuses extended XMP only where a changed field's property name follows a prefix or opens an element. IPTC ObjectName and Exif ImageDescription are not changed. The read and the edit are pinned against growth and hostile input, a gain-map Clear, two packets and a marked XPTitle, and the docs say where the title is stored and what an edit changes.
DetectFormat_OfMarkup_DoesNotDecodeIt measured one call against a 4 KB bound and failed twice in about 78 full-suite runs on this branch (net10.0 'long comment', net8.0 'unterminated doctype'), never in 25 runs of the class alone at main or here. The code it measures is unchanged since main, and it allocates 0 bytes on every row, even with the shared ArrayPool emptied first, so the cause of those two readings is not known; a measurement disturbed by the parallel run is the likeliest. The test now keeps the least of several runs (Bounds.LeastAllocated), as the other image allocation tests do. A copy of the input still fails every row.
…pictures in IsEmpty (#211) Title = "" on a FLAC, Ogg Vorbis, Opus or Ogg FLAC file stored an empty TITLE= comment, on a tagged file and through the tagless view, where MP4, ID3v2 and APE clear the field. A sweep of every format's text setters found the same gap elsewhere: Vorbis Movement and OriginalReleaseDate left an empty MOVEMENTNAME= or ORIGINALDATE=, ID3v2 PodcastFeedUrl stored an empty WFED frame, ASF Title, Artist, Album, Comment, Genre and Copyright read "" for a missing or cleared field, and a Matroska clear left the TITLE, ARTIST or COMPOSER that ffmpeg writes in its untargeted tag. An empty string now clears as null does, and every text getter reads null for a field with no text. A test sets "" on every writable text property of every format. The sweep also found Matroska Composer and AlbumArtist reading null and dropping every set, as MatroskaTag overrode only the lists. They now read the first name of Composers and AlbumArtists and write through them; writing the first name back keeps the others, as Artist does. Tag.IsEmpty looked only at the standard text fields, so a FLAC file holding only pictures, and a Vorbis, MP4 or APE tag holding only a cover, read as empty. The base IsEmpty now also requires no picture; ID3v2 and ASF already counted theirs.
Setting Title updated the TITLE tag and left Info/Title (RFC 9559 §5.1.2.9), so exiftool kept showing the old title and MediaInfo showed 'OldTitle / NewTitle'. Title = null and Clear kept it too (a known gap in the implementation guide). A title edit or Clear on a file whose Info has a Title now rewrites Info at exactly its length (MatroskaRewrite.RenderInfo, in the memory and the stream save): its Void children are dropped, the new Title goes in when it fits, and one Void pads Info back to its size, so nothing after it moves and no offset changes. A title that does not fit is left out of Info; with no Info/Title, exiftool and MediaInfo show the TITLE tag. On t.mka, ffprobe, exiftool, MediaInfo and this library all read the new title, short or long, and none after a clear.
…ere ffprobe shows them (#205) DiscNumber was written as PART_NUMBER at target 50, the tagging specification's disc. ffprobe shows every PART_NUMBER as the track number whatever its target, so a file with disc 2 and track 5 showed track=2 and track=5, and MediaInfo keeps the last PART_NUMBER it meets. A file that does not already keep its disc that way now gets ffmpeg's DISC ('n', or 'n/m' with TotalDiscs), in ffmpeg's untargeted tag or else a tag at target 50, the placement the album uses since #188; ffprobe, exiftool and MediaInfo show it as the disc. A file whose disc is already PART_NUMBER at target 50 keeps that layout. Five Matroska tests that pinned the old placement now pin this one. The track total had the same gap: TotalTracks was written as TOTAL_PARTS, which ffprobe shows only as a raw tag, and writing back the track and total of mkv/ffdisc.mka turned ffmpeg's PART_NUMBER=5/12 into 5 and TOTAL_PARTS=12. A file that does not already keep its total as TOTAL_PARTS (the spec's at 50, ffmpeg's untargeted one, or TagLib's at 30) now gets it after its track number, "n/m", which ffprobe shows as track=5/12 and MediaInfo as the track position; a total with no number to follow is still TOTAL_PARTS. Writing back the DiscNumber, TotalTracks or TotalDiscs read changes nothing; it rewrote a DISCNUMBER, TRACKTOTAL or TOTALDISCS that ffmpeg copied from FLAC. TotalTracks_Set_StripsTheSlashTotal pinned the old form and now pins this one.
…it cannot hold, instead of writing ? (#209, #216) A WAV file whose only tag is RIFF INFO saved a title such as '新标题 Ünï' as '??? Ünï', with success reported and the real text still in memory (#209): INFO was written as Latin-1. It was also read as Latin-1, so text ffmpeg wrote as UTF-8 read as mojibake, 新标题 as æ°æ é¢, where ffprobe reads it correctly (#216). AVI INFO already detects UTF-8. WAV INFO declares no character set. It is now read as AVI reads a list with no CSET (InfoText.Decode): a field of valid UTF-8 is UTF-8, and any other is Windows-1252, which fills the bytes 0x80 to 0x9F that Latin-1 leaves as controls. A changed value is written by the same rule (InfoText.EncodeByReadRule): Windows-1252 when every character has a byte there and those bytes read back as the value, else UTF-8. So whatever the reader returns, the writer stores and reads back unchanged, on every entry point and save, and no WAV INFO text is refused or written as '?': a tag copied from another file, Comment = Title, a typographic apostrophe (0x92). RiffInfoTag.SetCustomField takes any text, where it refused text outside Latin-1. The tag keeps each field's stored bytes, as AVI's does, so a field the caller does not change is written back with them. A property test checks the rule on random text from every read entry and every save, beside unchanged UTF-8 and Windows-1252 fields. Readers disagree on INFO text (measured): ffprobe reads it as UTF-8, exiftool as Windows-1252 unless given -charset RIFF=UTF8, and MediaInfo as Latin-1. A UTF-8 value shows correctly in ffprobe, a Windows-1252 one in exiftool, and a Latin-1 one in exiftool and MediaInfo; ffmpeg's own UTF-8 files show the same mojibake in exiftool and MediaInfo. AVI INFO with no CSET has the same reader, and refused a save that needed more than ASCII next to a field that is not UTF-8 (a cp1251 or Windows-1252 field): a value read from one field could not be written to another. That list is now written field by field by the same rule, the legacy bytes kept and no CSET added to misdeclare them. A list with a CSET keeps its rules, the refusal for a guessed field included. ID3v1 is Latin-1 by its format and wrote the same '?' in MP3, AAC and MPEG-PS. A save of those formats now fails, naming the field and writing nothing, when an ID3v1 field holds a character beyond U+00FF that no other tag of the file holds, as on a file whose only tag is ID3v1; Render throws with the same message, which points to Id3v2Tag. A value written through Tag to a file that also has ID3v2 reaches that tag, so it saves as before with a Latin-1 copy in ID3v1. A value longer than its ID3v1 field is still cut to the field, the format's limit; the docs now say so.
…es and H.263 video (#206) An mp4a sample entry was always reported as AAC, so mp3.mp4 and vmp3.mp4 read as AAC where ffprobe says mp3. The codec now comes from the entry's esds objectTypeIndication (mp4ra object types): 0x6B and 0x69 are MPEG audio, reported as Mp4AudioCodec.Mp3 with the esds bit rate; anything else stays AAC, what mp4a is for. The esds is found through the shared EsdsObjectType reader, which now takes where a sample entry's boxes start: 86 bytes into a visual entry, 36 into an audio entry, and 16 or 36 more in a QuickTime sound description of version 1 or 2. Those object types hold MPEG audio of any layer (ISO/IEC 11172-3, 13818-3), so the codec name comes from the layer in the header of the sound track's first frame, at its first stco or co64 chunk, read from the file bytes or the stream on every entry point, and named as MP3, AVI and MPEG-PS files name it (MpegAudioProperties.CodecName): mp2.mp4 reads "MPEG-1 Layer II", as MediaInfo shows Layer 2, where it read "MP3". QuickTime's .mp3 sound entry (mp3.mov) had no codec; it is Mp4AudioCodec.Mp3 and "MP3", and is found as the sound track as mp4a is. Video sample entries whose fourcc was echoed are named: Apple ProRes (apco, apcs, apcn, apch, ap4h, ap4x) and H.263 (s263, h263).
…eep them on every save (#208) test4.mkv from the Matroska test suite has an unknown-size Segment followed by 134 bytes of 0x0A filler before Info. ReadFromData and a non-seekable stream read Vorbis audio and 1280x720 Theora video; a path or seekable stream read returned no properties. The class: the three Segment walkers each had their own rule for bytes that do not parse as an element. The read from memory steps over them anywhere, the rewrite steps over them before the first element, and the stream collector, which gathers the metadata elements for a path or seekable stream read, stopped at the first one, so it kept nothing after the filler. It now skips to the next offset where an element that fits the Segment starts, as the read from memory does. The 18 Matroska samples read the same from a path, a stream and memory. The rewrite walkers (the one over bytes, the one over a stream, and the re-parse of the stream save's draft) refused filler after the first element with "Matroska segment cannot be bounded", a message that did not name the cause, so a file every read handled could not be saved: review 3's at.mka with filler after its first element, before its Cluster, after its last Cluster, or twice. They now keep filler anywhere as a piece of its own, as they already did before the first element, so the refusal is gone: a save with no edit writes the file back, and an edit keeps every filler byte, on the bytes and the path save, in a known-size and an unknown-size Segment. The save's walk peeks at most 12 bytes per filler byte; a hostile Segment of alternating junk and Voids saves in reads that grow with the file, pinned at 20 times its length. The skip's read starts at 4 offsets and doubles up to 64 KB, so a resync reads about as far as it scans. A window of 64 KB from every junk byte made a hostile file that alternates one junk byte with a 2-byte Void read 21 GB for 1 MB; it now reads 14 times the file, pinned on a path, a seekable stream and a SkipPictures read at 10 KB, 100 KB and 1 MB (CountingFileSystem, CountingStream). The other stream-side resyncs (AAC frames, MP3 frames, MPEG-PS start codes, Ogg pages) read at most 2.5 times the file on the same kind of hostile body, pinned by StreamResyncReadTests.
… parse (#207) A save, even with no edit, dropped every frame no branch of the reader handles: built/v23many.mp3 lost PCNT, MCDI, RVAD, ETCO, USER, COMR and an experimental frame, and a v2.2 tag lost CNT. Such frames are now kept as UnreadFrame: the ID (the v2.3 one for a v2.2 frame), both flag bytes, and the body as stored, still compressed, encrypted or unsynchronised when its flags say so. A save writes them after the frames this library renders, byte for byte when the tag is written in the version it was read in, and from a v2.2 tag written as v2.3 under the v2.3 ID with no flags, the bodies being the same in both versions (id3v2-00 §4, id3v2.3.0 §4) except LNK's, which is skipped. They are in FrameLists, so IsEmpty and Clear see them. The README, the Version remarks and the #187 CHANGELOG line, which said such frames are not written back, are corrected. A frame of an ID a branch reads, which that branch rejects, was dropped the same way: id3/bad23.mp3 kept 4 of its 18 frames (a 1-byte APIC, a short COMM, USLT, SYLT and GEOB, POPM, UFID and PRIV with no terminator, a truncated CHAP and CTOC, a TALB with an invalid encoding byte, a TPE1 of size 0). The branches now report whether they read the frame (ReadFrame), and a rejected frame, or one of size 0, is kept as stored too. It goes when the tag writes or removes every frame of its ID (a text or URL property set or cleared, Pictures = [], RemoveComments () and the other remove-all calls, Rating = null), so a set leaves one frame and a clear none; a rejected COMM or USLT goes with any write of Comment or Lyrics, and a rejected TXXX with a write or removal of the custom field its description names (the reader rejects a TXXX only when it has no terminator after its description, so the rest of the body is that description). A rejected WXXX, and a TXXX with nothing after its encoding byte, name no field and go only with Clear. A rejected v2.2 PIC is not written as an APIC, as its body differs.
decriptor
force-pushed
the
fix/wrong-values
branch
from
December 3, 2026 23:13
bfbd4a6 to
912aa9d
Compare
Owner
Author
|
Review: 0 blocking findings at 912aa9d. What was checked:
History: 17 commits, one per issue (or per closely related pair), so this should be rebase-merged rather than squashed. |
This was referenced Dec 3, 2026
Closed
decriptor
added a commit
that referenced
this pull request
Dec 4, 2026
#192 and #197 are one defect in the WAV and AIFF chunk walks, twins: the read from memory and the read from a stream kept different chunks, and the bytes after the form were lost. One rule in Core (ChunkExtent, FormTrail, TrailingTagChunk) fixes both. #203 is the WAV twin of #197's AIFF path save, which copies a chunk of any size from the source. Each part below was red on the commit before it when it was its own commit. == #192: Read a WAV data chunk of unknown size the same from memory ffmpeg writes a data chunk size of 0xFFFFFFFF when its output is a pipe; the samples run to the end of the file, and ffprobe reads their duration (2.1196 s for the review's wav-ffff.wav). A stream or path read kept the chunk with the bytes present and read that duration. A read of bytes in memory (MediaFile.ReadFromData, WavFile.Read, ReadFromFile) went through RiffChunk.TryParse, which refused any size past int.MaxValue: the walk stopped there, the data chunk was lost, the duration read 0 and a save was refused for having no data chunk. Two walks of one structure disagreed on one rule. Both walks now keep a chunk by one rule, RiffFile.PresentBytes: its bytes present, up to its size and never past the end of the RIFF form. The span walk passes the form's end into RiffChunk.TryParse (which kept bytes up to the end of the data, so 128 bytes after the form of the review's wav-ffff-trailing.wav were samples and ReadFromData read 2.00145 s against 2.0 s), and the stream walk copies a chunk other than data whose size is past int.MaxValue from the bytes present, as the span walk does (it kept it empty, so a LIST INFO of size 0x80000000 had a title from memory and none from a stream: wav-list-8000.wav; ffprobe reads the title). Only bytes present past int.MaxValue, which no copy can hold, stay in the file like samples. The walks still end at a chunk that runs past the form. A save from any read writes the samples present with their size. Bytes after the form are not samples, but they are the file's, and a save dropped them: it wrote the form alone, so bytes that are no chunk, a chunk after the form, and the samples past a RIFF size short of them were lost. They are now written after the form as they were (Core FormTrail, which #197 uses for AIFF too). A read of the bytes holds them; a stream read leaves them in the file, as its last bytes, which is where every save writes them, so the streamed save copies them from the end of the source, after a save over that source as well, and Render loads them with the samples. The RIFF size of a save does not count them, as it did not on the read. An id3 chunk a tagger appended right after the form without growing the RIFF size (exiftool and ffprobe read it; review 6's trail-id3.wav) is read as the file's tag chunk when the form holds none, on every entry point, read from bytes, a stream and SkipPictures (Core TrailingTagChunk: a whole chunk right after the form whose body is an ID3v2 tag); the bytes after it are the trail. So a save writes the tag in the form and no stale copy stays after it: carried, it left an old title that ffprobe showed beside the new one. A chunk with that identifier whose body is no tag, or one not right after the form, is carried as it is. Review 7 found the shapes the read left stale for ffprobe, and one it dropped. The chunk is now named "id3 " or "ID3 " (either case of the identifier the format reads its tag from). More such chunks right after it, or right after a form that has its own tag, are superseded by the form's tag: a save that writes the tag other than as it was read (an edit, or removing it; the tag rendered against the tag read, rendered) drops them, so ffprobe shows no old title beside the new one and a removed tag does not come back from them, and a save that leaves the tag as read carries them as they were (FormTrail.For). A SkipPictures read that left a picture out of the tag counts as rewritten, as a full read cleared of its pictures is (the stripped copy says whether it left one out). A chunk whose ID3v2 header is followed by no field is no longer taken as the file's tag, which a save then dropped (48 bytes); it is carried, so a chunk the read does not take is always kept as it was. A chunk cut short or declaring more than the file holds is carried as it was: it is not a whole tag, and ffprobe still shows its title beside a new one. Tests, red on the previous commit for 11 of 27, and 21 of 160 for the property test (all on main too): - RiffWalkAgreementTests: fmt, data, LIST INFO and an unknown chunk, last in the form or not, given a size 1 and 1,000 past its bytes, 0x7FFFFFFF, 0x80000000 and 0xFFFFFFFF, with and without 128 bytes after the form and with a placeholder form size (160 files): the ten entry points read the same duration, format and title. Main fails 21 (data chunks counting bytes after the form, and oversized chunks the span walk dropped); the first version of this commit fixed 12 of those and broke 32 cells main had right (every fmt and LIST size past int.MaxValue), 41 in all (r3/red in the fix report). Its matrix also has a declared size below the true size and forms of size 0, 4, half the form and larger than the file (1,152 rows with the save rows), and each row is saved after a read from memory and after a stream read: both write the same bytes or end the same way. FormEnd_BoundsTheChunks pins the rule itself, not only agreement: bytes after the form are not samples, and a chunk past the form's end is not read (a mutant that ignores the form's end changes every walk alike and passes the agreement rows). Main fails 185 of those 1,153. - WavUnknownDataSizeTests: a piped file with a data size of 0xFFFFFFFF, and one of 0x80000000, reads 2 s on all ten entry points; a save after a format path read, a path read and an async path read keeps the samples, in a data chunk of their size. - WavFileSavePreservationTests: the four DataChunkSizeSentinel tests pinned the refusal that followed from the lost chunk (the saves and Render failed rather than write a WAV without its samples); they now pin that the save and Render keep the samples. - FormTrailSaveTests: a WAV with an id3 chunk right after the form, that chunk then 37 bytes that are no chunk, those bytes alone, the bytes then the chunk, a RIFF size 16 bytes short of the samples, the chunk after a form whose data chunk is empty, a form with an id3 chunk of its own then the chunk, and a chunk with that identifier whose body is no tag, read from a path, a path async and memory, saved to a path and over the source, sync and async, with and without a new title: the read finds the trailing tag where there is one; the saved file is the form, then the bytes carried as they were, and reads with the source's duration and the title it was given or read; with no edit the samples are one run again. Every entry point (path, async path, bytes, stream, async stream, and the three SkipPictures reads) reads the same title and duration. The tag rows use v2.2, v2.3 and v2.4 tags. Red in two steps: the trail's 96 rows all failed on the previous commit (round 6), and with the trail in, 100 of 250 failed before the tag read (every row of the shapes with a tag read, and their parity rows; F/r7/red-tag-192.log). Mutants of each read, the tag read in each walk, the tag check, the version guard, Render, the streamed save, the load and the copy's offset fail them (F/r6/mut/results-trail-192.txt, F/r7/results-tag-v2.txt). - FormTrailSaveTests, round 8: the chunk named "ID3 ", two chunks after the form, a chunk with an ID3v2.3 header and no field, alone and after a form with a tag, and a chunk cut 10 bytes short. Removing the tag drops the superseded chunk on every read and save, and a SkipPictures read renders what a full read cleared of its pictures renders (a picture in the form's tag, in the tag read from after the form, and a tag after the form that holds a picture alone). 99 of 402 failed before (F/r8/red-tag-192.log); mutants of the case rule, the field check, the picture flag, each walk's superseded count, Render's and the streamed save's choice, and the removal fail them (F/r8/results-tag8.txt). == #197: Read and save AIFF chunks by one rule, memory and stream The AIFF twin of #192's RIFF fix. A read of bytes in memory walked the chunks to the end of the data and ignored the FORM size; a stream read stopped at the FORM's end. The span walk also dropped a chunk whose size ran past the data or past int.MaxValue, where the stream walk kept the bytes present, and the stream walk kept a non-SSND chunk past int.MaxValue empty. The review's aif-form-0.aif (FORM size 0; also 4 and 12) read 2.0 s from memory and no audio properties on the seven other entry points, on main too; ffprobe rejects it. ChunkExtent (Core) is now the one rule both chunk families use: a form ends at its declared size, or at the end of the data when that size is the 0xFFFFFFFF placeholder or runs past it; a chunk holds its bytes present, up to its size and never past the form's end. RiffFile's PresentBytes moves there; AiffChunk.TryParse takes the form's end and keeps such a chunk with its declared size and the bytes present (it returned false); the stream walk copies a non-SSND chunk past int.MaxValue from the bytes present, and leaves only bytes past int.MaxValue in the file, as the RIFF walk does. The span walk needs no stop of its own at a cut chunk: its declared size puts the next offset past the FORM's end (a mutant that removed such a stop survived, so it is gone). A chunk kept with its declared size past its bytes is now saved by the bytes it holds, as a WAV chunk is: AiffChunk.RenderedSize (the header, the bytes present and their pad) sizes Render's buffer and the file in Render, and the streamed save writes a skipped SSND with the size and pad of its bytes present. They sized and wrote the declared size, so a file of a few hundred bytes that declared a 256 MB chunk made a save allocate 512 MB, a declared size near 2 GB or past it threw "Cannot render an AIFF file larger than supported memory.", and a header that kept the declared size swallowed the ID3 chunk written after it. The review's aif-ssnd-ffff.aif (SSND 0xFFFFFFFF, the placeholder a streamed writer leaves; ffprobe reads 2.0 s) and aif-comm-19.aif (COMM 19, so COMM takes a byte of SSND's header) threw that way from a path read, on main too; they now save and read back as the source did. The streamed save copied only the bytes present; its header, pad and FORM size were the declared ones. A stream read kept such a chunk before this commit, so #192 has the same failures; keeping it on a read from memory too made them reachable from every entry point. RIFF chunks are already written by the bytes they hold (RiffChunk.RenderedSize, and the WAV streamed save's PresentBytes), and DSF and DSDIFF size their saves from the bytes present; neither uses the declared size for a buffer. A stream read leaves an SSND in the file and records it, so a save copies it from the source. It recorded one only up to int.MaxValue bytes; a larger one (review 4's big.aif, a 2,281,701,444-byte file) was left in the file unrecorded, so a save took the in-memory path and, with chunks now written by the bytes they hold, wrote an SSND with no bytes and reported success. Over the source, that destroyed the file; main threw instead. Every SSND left in the file is now recorded, whatever its size, and the streamed save copies it in pieces: only the FORM's 32-bit size bounds the file, and a save past it fails with "Cannot save an AIFF file larger than its 32-bit FORM size." and writes nothing (the streamed save threw "larger than supported memory" for any chunk sum past int.MaxValue). The same sweep: DSF and DSDIFF save a 2 GB sound by copying it; WAV refuses it before writing ("does not fit in memory"), as on main; no render treats a chunk left in the file as empty. Bytes after the FORM are written after it as they were, as a WAV save writes the bytes after its RIFF form (#192, Core FormTrail), and an ID3 chunk right after the FORM is read as the file's tag chunk when the FORM holds none, on every entry point (Core TrailingTagChunk, as #192 reads a WAV's). The real taglib-samples sample.aif has its ID3 chunk after the FORM's declared end; exiftool reads its Title, Album and Artist (ffprobe and MediaInfo read no tag there). A save with no edit dropped the chunk (177,704 bytes to 176,454, on main as well), and a FORM size short of the sound dropped the sound past it. The first version of this commit carried the chunk without reading it, which left the old tag after an edit for a reader that reads past the FORM (review 6). Now the tag is read, from bytes, a stream and SkipPictures, so a save writes it in the FORM and no stale copy stays after it; any other bytes after the FORM, and a tag chunk when the FORM has its own, are carried as they were. The tag read takes ID3v2.2, v2.3 and v2.4 tags: sample.aif's tag is ID3v2.2, which #186's reader reads whole and #187 writes back as ID3v2.3. After an edit, exiftool, ffprobe and MediaInfo show only the new title, with the artist, album, comment and the other fields kept. The tag chunks after the FORM follow #192's rule (review 7): the chunk is "ID3 " or "id3 ", one whose ID3v2 header is followed by no field is carried, and more such chunks right after the one read, or right after a FORM with its own ID3 chunk, are dropped by a save that writes the tag other than as it was read and carried by one that does not (AiffFile.TagRewritten, against the tag the last ID3 chunk that reads holds, as the read takes it). The test AIFF builder declared a FORM 16 bytes short of its chunks, so a stream read never reached SSND and a read from memory ignored it. It now declares the true size; the SkipPictures fixture that rendered an AIFF seed after a stream read reads it from memory instead, as a stream read leaves the sound in the stream. Tests, red on the previous commit for 351 of 685, and 37 of 79 for the save tests; the B1 tests are red on this commit's first version (9fe27c89) for 16 of 40: - AiffWalkAgreementTests: COMM, SSND, NAME and an unknown chunk, last or not, a size below the bytes, +1, +1000, 0x7FFFFFFF, 0x80000000, 0xFFFFFFFF, with and without 128 bytes after the form, in a FORM of its true size, the placeholder, 0, 4, 12, half and larger than the file (672 files): the ten entry points read the same. 347 failed. - FormEnd_BoundsTheChunks: a NAME past the FORM's end is not read, and a FORM larger than the file reads every chunk, on all ten entry points: the rule itself, which a mutant that ignores the FORM's end would keep in agreement. - AiffChunkTests: the three tests that pinned TryParse refusing a size past the data or past int.MaxValue now pin the size and the bytes present. - TruncatedLastChunkSaveTests: a tiny AIFF and a tiny WAV whose last chunk (the sound, a chunk a reader knows, an unknown one) declares 256 MB, 256 MB and one byte, 0x7FFFFFF0, 0x80000000 or 0xFFFFFFF0, in a FORM of its true size or the placeholder (60 rows), read from a path, a stream and memory, saved as read and with a new title, to a path and over the source, sync and async: each save writes a file no longer than the source and the ID3 chunk, which reads as the edited file did, or fails and writes nothing, and a sync save allocates under 16 MB. All 30 AIFF rows failed (a throw, 512 MB allocated, or the title lost); the 30 WAV rows pass on #192. - AiffOversizedChunkSaveTests: both review repros, read from a format path, a path and memory, saved to a path and over the source, sync and async: each save succeeds, writes the FORM size of the file and every chunk with the size of its bytes, and reads as the source did (18 rows; the 6 after a path read failed). - PathSaveCancellationTests: the test that pinned the throw for a declared size past memory now pins the cancelled save's failure. - BigSoundSaveTests: a WAV, AIFF, DSF and DSDIFF file whose sound chunk holds 0x88000000 bytes, as Kit/SparseFileSystem files (the sound is a run of a pattern that costs no memory and is checked byte by byte as a save streams it), read from a path sync and async, retitled, and saved to a path and over the source, sync and async: AIFF, DSF and DSDIFF keep the sound after the same chunk header and read back as the edited file; WAV fails and writes nothing. An AIFF whose FORM is 4 GB less 18 bytes, retitled, fails with the FORM message and writes nothing. Review 5's shapes: an odd SSND with its pad byte and a chunk after it keeps the sound, the pad and the chunk; a FORM of 0xFFFFFFFE saved as it is copies all 4 GB of the sound. Each saved sound is exactly the source's length. 25 of 49 failed on 9fe27c89 (every AIFF row). - FormTrailSaveTests gains the AIFF rows of #192's shapes (the empty sound is a FORM with no SSND chunk), with v2.3 and v2.4 tags after the form. Red in two steps: the trail's 96 AIFF rows failed on the previous commit (round 6), and the 100 AIFF rows of the tag shapes failed on this commit's code without the AIFF tag read (100 of 500; F/r7/red-tag-197-v2.log). Mutants of each read, Render, the streamed save, the load, the tag read in each walk, the tag check and the version guard fail them (F/r6/mut/results-trail-197.txt, F/r7/results-tag-v2.txt). - Round 8: the AIFF rows of #192's new shapes, the removal test and the SkipPictures render test. 50 of 804 failed with no superseded chunks in the AIFF walks (F/r8/red-tag-197.log); mutants of each walk's count, the picture flags, Render's and the streamed save's choice and the removal fail them (F/r8/results-tag8.txt). == #203: Copy a WAV chunk of any size from the source on a path save A WAV path save refused any chunk past the array limit (about 2 GB), with "Cannot save a WAV file whose sample data does not fit in memory.", though the save never holds the chunk: it copies it from the source in 64 KB pieces (WritePlanned). A 2.28 GB WAV, or one whose data chunk ends with the 0xFFFFFFFF size a streamed writer leaves, could be read and retitled but not saved. On main. An AIFF save copies its sound of any size from the source since #197; WAV now does the same. WavFile.SaveFromSource drops the refusal and sums the planned pieces instead: a save whose RIFF size (4 + the chunks) would pass 32 bits fails with "Cannot save a WAV file larger than its 32-bit RIFF size." and writes nothing, as AIFF's FORM guard does. Every piece is 8 bytes, the bytes present and a pad, so the size is even and 0xFFFFFFFE is the largest; it saves. The in-memory render and the span saves still load the samples and keep the memory refusal (TryLoadSkippedSamples), as AIFF's TryLoadSkipped does. This reverses two tests that pinned the old rule, that a save of such a file "fails closed"; they now pin the new one: - WindowedReadDefectTests.Read_DataChunkPastTwoGigabytes_ KeepsTheFollowingTitleAndRefusesTheSave is now ..._KeepsTheFollowingTitleAndSavesTheSamples: the 2 GB data chunk is copied whole, and the title after it reads back. - WindowedReadEdgeTests.Save_DataChunkJustOverTheArrayLimit_FailsClosed is now ..._CopiesTheSamples: every sample is copied and the RIFF size is the file's length less 8. Both now use the kit's SparseFileSystem, and their private copies of it are gone. Tests, red on the previous commit for 27 of 116: - BigSoundSaveTests gives WAV rows for each shape AIFF has: a sound past int.MaxValue, an odd sound followed by another chunk, a container of 0xFFFFFFFE bytes saved whole, and a save that would pass 32 bits failing and writing nothing; read from a path and a path async, saved to a path and over the source, sync and async. Every WAV row failed (25), and the two rewritten tests above; the AIFF rows pass. - Mutants: removing the RIFF guard, or restoring the refusal, fails them. Making the guard >= is equivalent, since the size is always even (F/r6/mut/results-203.txt). - On #186 (the branch now sits on it): the v2.2 shape is read like the v2.3 and v2.4 ones, and sample.aif from the corpus is read with its title on every entry point and saved with no edit or a new title, sync and async, as one tag in the FORM keeping its album and artist. 54 of 808 failed while v2.2 was carried (F/r8/red-v22-C.log).
4 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Stops readers from returning a value the file does not store, and stops saves from dropping or mangling one it does. Each issue has its own commit; the four commits with no issue number fix gaps found while working on these.
f74f6321AC/DCreads as one performer, as ffprobe, exiftool and MediaInfo read it."(17)"as Rock andn/mtrack and disc numbers are unchanged.38e8d040(#187)TCP,TS2,TSA,TSC,TSP,TST.128db2d4(#188)ALBUM, and an album edit keeps the title that ffprobe and MediaInfo show.50938b3btkhdmatrix), not as an audio sample rate. NewMp4File.VideoProperties.6d6d04cfProjectionPoseRoll(RFC 9559 §5.1.4.1.28.46).e0cdd294covrrole and every APECover Art (<role>)key survive a save. APE keys read only a role name, not numbers or comma lists.3cccb29a644d4b2b9540e0fadc:title, and everyXPTitleis removed, so ExifTool, Exiv2, ImageIO and TagLib# show the new title.55f036f1843e1644(#211)""clears the field in every format, asnulldoes, and pictures count inIsEmpty. MatroskaComposerandAlbumArtistnow read and write.8e18b880(#210)Info/Titlein place, so exiftool and MediaInfo show the new title.cc96c6da(#205)DISC, notPART_NUMBERat target 50, which ffprobe shows as the track number.20334362(#209, #216)?. ID3v1 refuses text it cannot hold instead of writing?.78410c94(#206)mp2.mp4reads "MPEG-1 Layer II", not AAC); ProRes and H.263 are named.ac7aa9a4(#208)test4.mkvnow reads its audio and video from a path or a stream. The resync scan grows from 4 bytes, so junk cannot make the reader read far more than the file.912aa9dd(#207)PCNT,MCDI,RVAD,ETCO,USER,COMR, experimental frames, v2.2CNT) are written back instead of dropped.The README, ROADMAP, docs and CHANGELOG describe the ID3 versions and each value stored.
Motivation and Context
Each change fixes a value that did not match what the file stores, or one lost on a save. Behaviour was checked against ffprobe, exiftool, MediaInfo and, for JPEG, Exiv2 and macOS ImageIO.
Fixes #187
Fixes #188
Fixes #205
Fixes #206
Fixes #207
Fixes #208
Fixes #209
Fixes #210
Fixes #211
Fixes #216
Related, not closed:
CSETis read as on main.Type of Change
Behaviour callers may rely on that changes:
Tagon a tagless MP3, AAC, DSF, DFF, MPEG-PS, AIFF, WAV, FLAC, WavPack, Monkey's Audio, Musepack or MP4 file is no longernull. Code that testsfile.Tag is nullto mean "no tag" must test the stored tags instead.""clears it; an empty field readsnull.Versionstill reports 2 for the tag that was read).DISC.Public API, from the snapshot:
Mp4File.VideoProperties,VideoProperties.Rotation, andAlbumArtistandComposeroverrides onMatroskaTag.Checklist
dotnet format --verify-no-changespasses)dotnet test): see TestingImplementation guide (docs/IMPLEMENTATION-GUIDE.md)
Testing
At head
912aa9dd: a Release build of all target frameworks with 0 warnings, anddotnet format --verify-no-changesclean.Additional Notes
The branch history was rewritten into one commit per issue, so this update was force-pushed.