Repository navigation
GEMDRIVE: return the right last byte on an odd-sized read - #24
Open
Chati-SidecarTridge wants to merge 1 commit into
Open
Chati-SidecarTridge wants to merge 1 commit into
Chati-SidecarTridge wants to merge 1 commit into
Conversation
handleReadBuffCall() swapped the chunk's byte pairs rounding the count down, so on an odd count the pair holding the ST's last byte stayed unswapped and Fread() returned a stale byte from an earlier read. Round up, as handleWriteBuffCall() already does. Fixes sidecartridge#21
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.
Fixes #21.
The bug
handleReadBuffCall()swaps the chunk's byte pairs for the m68k, but rounds the count down:The ST copies
bytesReadbytes from the window. On an odd count, its last byte (even offsetbytesRead - 1) comes from the other half of the final, unswapped pair, i.e.dst[bytesRead]on the RP, whichf_read()did not write. SoFread()returns the right count but a stale last byte, left over from an earlier read. Even-sized reads are fine.Effect: any odd-length file read to its end gets a wrong last byte. Programs (
.PRG) of odd length crash with bombs. A customer reported the same thing by email (3 bombs on odd-length PRGs, workaround: pad the file with one$00byte).The fix
Round up instead, as
handleWriteBuffCall()already does for the other direction:The extra byte swapped is
dst[bytesRead], still inside the window: an oddbytesReadis at mostGEMDRIVE_READ_BUFFER_SIZE - 1(4095), and the buffer is 4096 bytes. The ST only copiesbytesReadbytes, so the garbage now in the unused half of the last pair is never read.I checked the other swaps in
gemdrive.c:writeAppFreeBytesSwapped()is only called with 14 bytes, andreadPayloadAtariPath()rounds down on purpose for a NUL-terminated string. Neither has the problem.Checked
rp/build.sh pico_w releasebuilds clean with ARM GNU Toolchain 14.2.rel1, no new warnings.target_firmware.hunchanged (RP-side change only).Fread2 bytes ofB.BIN, then 1 byte ofA.BIN, expectA.BIN's first byte), and running an odd-length PRG from GEMDRIVE without padding.