Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MKA file gets unreadable after modifying it / SeekPoints value vs. headers length #4

Open
Zeugma440 opened this issue Aug 16, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Zeugma440
Copy link
Contributor

Hey there~

I've observed certain files (e.g. that one) become unreadable by MP3tag and foobar2000 after being modified with SpawnDev.EBML.

After a few tries, and with the help of mkvvalidator, I realized the problem is as follows :

  • EBML headers have their size encoded in a VINT (variable integer). This data structrure is supposed to take up just the right quantity of bytes for the value you want to store.
  • Certain softwares (including SpawnDev.EBML) do follow that rule and encode small numbers, say 35, as a VINT by using one single byte
  • Other softwares don't want to bother with over-optimization and always use 8 bytes even though they'd need just one. That's the case with the sample file linked above.
  • As a consequence, when SpawnDev.EBML rewrites such a file, there are a bunch of EBML headers that get rewritten, using 1 or 2 bytes instead of the default 8 they were initially lazily written with
  • I discovered that the values of the SeekPositions don't take these header size variations into account when being rewritten, thus resulting in file corruption. SpawnDev.EBML might assume all VINTs are written in an optimal way

image

(here, the difference in bytes between the position signalled by the SeekPoint and the actual position matches the difference in bytes between the sum of corresponding initial header sizes encoded with 8 bytes and the sum of the same header sized encoded optimally)

=> From where I stand, there are two ways to fix this :

A/ Make sure SpawnDev.EBML writes EBML headers while keeping the initial number of bytes their size has been initially encoded with

or

B/ Make sure any position shift is reflected in SeekPosition values, including shifts caused by VINT size changes

What's your take on that issue?

@LostBeard LostBeard self-assigned this Aug 17, 2024
@LostBeard LostBeard added the bug Something isn't working label Aug 17, 2024
@LostBeard
Copy link
Owner

I am working on option B. It is more flexible and the right way to do it.

Thank you for finding this issue. 👍

@LostBeard
Copy link
Owner

Some of the spec does give suggestions to make files easier to edit after they are created. Leaving the SeekPosition the max (8 bytes) may be one of those suggestions.

@Zeugma440
Copy link
Contributor Author

Zeugma440 commented Aug 22, 2024

From what I've tested so far, it definitely looks better, but MP3tag still refuses to open edited files.

mkvvalidator is currently frowning at the 2nd SeekHead (the one near the end of the file), as it appears to be desynchronized

image
(the source file is the same as before, after adding some tags and an image)

Could you make it so all SeekPoints are updated when moving things around?

Thanks in advance 😄

PS : I'm using MP3tag to check embedded pictures inside MKA files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants