-
Notifications
You must be signed in to change notification settings - Fork 8
Description
The tool seems to truncate the last byte of the file.
As far as I understand in this mode, the output file should always be a multiple of 5 bytes. My tool which which reads the .SAV file whines that there is missing data.
It looks like the code intentionally does this, but I'm suspicious that even attempting to truncate the file fundamentally broken. It looks to me like the existing code truncates the last byte of the file just because it is zero - not because the file size is wrong.
I don't know what the correct fix is. I don't have a lot of test cases using the other modes and I don't know if this breaks something else.
Previous versions of the code had the following comment:
/* * This code attempts to remove trailing nulls from text data. Be careful * not to remove trailing zeros from binary data. */
I added some printf() statements to the code and in my case, the last 5 bytes (last 36-bit word) in the buffer are:
buffer[bufpos-0] = 0x00
buffer[bufpos-1] = 0x00 <- should be last byte in file
buffer[bufpos-2] = 0x30
buffer[bufpos-3] = 0x00
buffer[bufpos-4] = 0x00
buffer[bufpos-5] = 0x2b
bufpos is 2235
A hex dump of a file created with the Github code and 127674 bytes long looks like:
0001f2a0: 00 90 4f 44 5e 77 27 00 00 00 01 91 03 77 5d 21 0001f2b0: 2b 7f 7b 20 00 30 2b 00 00 30
A hex dump of a working file (truncation code removed) and 127675 byte long looks like:
0001f2a0: 00 90 4f 44 5e 77 27 00 00 00 01 91 03 77 5d 21 0001f2b0: 2b 7f 7b 20 00 30 2b 00 00 30 00
The command line I'm using is:
t10backup -i -x diagnostics..dsrpa.sav -f ks_diag_gs.tap
I modified the code as follows:
void WriteBlock (void)
{
char buffer [5*512];
long bufpos, index;
unpackdata ();
for (index = headrh [G_LND], bufpos = 0;
index < (headrh [G_LND] + headrh [G_SIZE]); index++)
{
pars_5chars (index, &buffer [bufpos]);
bufpos += 5;
}
- if (headlh [G_FLAGS] & GF_EOF)
- {
- for (index = 1; index < (eightbit ? 4 : 5); index++)
- {
- if (buffer[bufpos - 1] == (char) 0)
- bufpos--;
- }
- }
(void) fwrite (buffer, sizeof (char), bufpos, destination);
}