kaitai-io / kaitai_struct_formats

Kaitai Struct: library of binary file formats (.ksy)
http://formats.kaitai.io
711 stars 204 forks source link

S3M decoding fails with empty patterns #607

Open AntonioND opened 2 years ago

AntonioND commented 2 years ago

I don't know if this is part of the specifications, because S3M seems to be a very loosely-defined format.

When a pattern is completely empty, OpenMPT likes to have a pattern_ptr that is simply 0 (instead of pointing at an array of 64 empty rows). At the moment, the decoder thinks that the para pointer of value 0 is correct, and it starts reading bytes at the start of the file. I'm using Python, and I would expect an exception or something when trying to read data from that pattern.

https://github.com/kaitai-io/kaitai_struct_formats/blob/b90cf2957608ad5fb24954cfe344e95cb0993d2a/media/tracker_modules/s3m.ksy#L195

I've attached a file that shows this issue:

empty_pattern.s3m.zip

For more context, I'm creating a Python script that converts S3M files into a custom format so that it can be played on the Game Boy Advance: https://github.com/AntonioND/gbt-player/blob/ef3ff9f5474e170b0b2fdf765c337e398197b972/gba/s3m2gbt/s3m2gbt.py