Skip to content

ADFS validation code is in error #38

@fysnet

Description

@fysnet

The following code will fail on numerous images.

static bool adfs_validate_map_sector(const unsigned char *sector)
{
uint32_t sum = 0;
for (int i = 0; i < 255; ++i) {
sum += sector[i];
if (sum > 0xff) {
sum = (sum & 0xff) + 1;
}
}
return (uint8_t)sum == sector[255];
}

This code starts at byte 0 and goes to byte 254. The ADFS specs say you must go from byte 254 to byte 0.

At first, you might think that it doesn't make a difference, but the specs also state:

so the carry bits (except for the last one) are included

If you try to mount the image from, https://8bs.com/pool/tbi/adfs/tbi35a.zip, your code should fail since the first byte (the last byte in the validation) will set the carry. However, since you are not to include the carry in the last addition, this code fails to validate the image.

One way to fix it (if you start at 254 and go to 0):

sum = (sum & 0xff) + ((i > 0) ? 1 : 0);

However, this adds 253 unnecessary conditional instructions in the code :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions