Skip to content

Commit

Permalink
Improve sanity check for DNP images
Browse files Browse the repository at this point in the history
DNP images with > 256 tracks probably could be supported, but this
would require changes in multiple places where currently an uint8
is used for the track index.

The track count is limited to 255 instead of 256 to avert bugs in
loops like

  for (t=1; t<=get_param(part, LAST_TRACK); t++) {
    [...]
  }
  • Loading branch information
thierer committed Sep 23, 2022
1 parent 077d4f3 commit 3fc7320
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/d64ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ uint8_t d64_mount(path_t *path, uint8_t *name) {
}

/* Not recognized as neither D41, D71 nor D81 image; last try is DNP */
if ((fsize % (256*256L)) != 0) {
if ((fsize == 0 || fsize % (256*256L)) != 0 || fsize / (256*256L) > 255) {
set_error(ERROR_IMAGE_INVALID);
return 1;
}
Expand Down

0 comments on commit 3fc7320

Please sign in to comment.