Menu

#479 PZX files are broken on big-endian systems

NextRelease
closed-accepted
nobody
None
5
2021-03-06
2021-03-04
No

Test 28 fails on big-endian machines (powerpc, s390x, hppa, ...)

Test 28: Zero tail length PZX file... FAILED
expected 855 tstates and flags 96, got 22275 tstates and flags 96

And indeed the test expects 855 (0x0357) but gets 22275 (0x5703).

The PZX data block specification defines the following fields:

offset      type             name  meaning
0           u32              count bits 0-30 number of bits in the data stream
                                   bit 31 initial pulse level: 0 low 1 high
4           u16              tail  duration of extra pulse after last bit of the block
6           u8               p0    number of pulses encoding bit equal to 0.
7           u8               p1    number of pulses encoding bit equal to 1.
8           u16[p0]          s0    sequence of pulse durations encoding bit equal to 0.
8+2*p0      u16[p1]          s1    sequence of pulse durations encoding bit equal to 1.
8+2*(p0+p1) u8[ceil(bits/8)] data  data stream, see below.

The first two are read correctly using libspectrum_read_dword() and libspectrum_read_word(), but the last two before the data stream are simply copied using memcpy() without correcting the byte order.

Since PZX stores that information in little-endian order, this is broken on big-endian machines.

I'm attaching a patch with the fix.

1 Attachments

Discussion

  • Fredrick Meunier

    • status: open --> closed-accepted
    • Group: future --> NextRelease
     
  • Fredrick Meunier

    Thanks, good catch.

     

Log in to post a comment.