Attachment "tclZipfs.patch" to
ticket [ad7bafd5e1]
added by
juliannoble2
2024-10-09 14:03:37.
--- tclZipfs_orig.c Sat Oct 05 06:09:53 2024
+++ tclZipfs.c Wed Oct 09 21:57:28 2024
@@ -337,11 +337,12 @@
static void SerializeCentralDirectoryEntry(
const unsigned char *start,
const unsigned char *end, unsigned char *buf,
- ZipEntry *z, size_t nameLength);
+ ZipEntry *z, size_t nameLength, long long dataStartOffset);
static void SerializeCentralDirectorySuffix(
const unsigned char *start,
const unsigned char *end, unsigned char *buf,
- int entryCount, long long directoryStartOffset,
+ int entryCount, long long dataStartOffset,
+ long long directoryStartOffset,
long long suffixStartOffset);
static void SerializeLocalEntryHeader(
const unsigned char *start,
@@ -3356,6 +3357,8 @@
int count, ret = TCL_ERROR;
Tcl_Size pwlen = 0, slen = 0, len, i = 0;
Tcl_Size lobjc;
+ long long dataStartOffset;/* The overall file offset of the start of the
+ * data section of the file. */
long long directoryStartOffset;
/* The overall file offset of the start of the
* central directory. */
@@ -3528,6 +3531,10 @@
}
memset(passBuf, 0, sizeof(passBuf));
Tcl_Flush(out);
+ //dataStartOffset = zf->baseOffset; // REVIEW
+ dataStartOffset = Tcl_Tell(out);
+ } else {
+ dataStartOffset = 0;
}
/*
@@ -3579,7 +3586,7 @@
name = Tcl_DStringValue(&ds);
len = Tcl_DStringLength(&ds);
SerializeCentralDirectoryEntry(start, end, (unsigned char *) buf,
- z, len);
+ z, len, dataStartOffset);
if ((Tcl_Write(out, buf, ZIP_CENTRAL_HEADER_LEN)
!= ZIP_CENTRAL_HEADER_LEN)
|| (Tcl_Write(out, name, len) != len)) {
@@ -3599,7 +3606,7 @@
Tcl_Flush(out);
suffixStartOffset = Tcl_Tell(out);
SerializeCentralDirectorySuffix(start, end, (unsigned char *) buf,
- count, directoryStartOffset, suffixStartOffset);
+ count, dataStartOffset, directoryStartOffset, suffixStartOffset);
if (Tcl_Write(out, buf, ZIP_CENTRAL_END_LEN) != ZIP_CENTRAL_END_LEN) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"write error: %s", Tcl_PosixError(interp)));
@@ -3756,7 +3763,9 @@
const unsigned char *end, /* The end of writable memory. */
unsigned char *buf, /* Where to serialize to */
ZipEntry *z, /* The description of what to serialize. */
- size_t nameLength) /* The length of the name. */
+ size_t nameLength, /* The length of the name. */
+ long long dataStartOffset) /*The overall file offset of the start of the
+ * Data section of the file. */
{
ZipWriteInt(start, end, buf + ZIP_CENTRAL_SIG_OFFS,
ZIP_CENTRAL_HEADER_SIG);
@@ -3781,7 +3790,7 @@
ZipWriteShort(start, end, buf + ZIP_CENTRAL_IATTR_OFFS, 0);
ZipWriteInt(start, end, buf + ZIP_CENTRAL_EATTR_OFFS, 0);
ZipWriteInt(start, end, buf + ZIP_CENTRAL_LOCALHDR_OFFS,
- z->offset);
+ z->offset - dataStartOffset);
}
static void
@@ -3790,6 +3799,8 @@
const unsigned char *end, /* The end of writable memory. */
unsigned char *buf, /* Where to serialize to */
int entryCount, /* The number of entries in the directory */
+ long long dataStartOffset, /* The overall file offset of the start of the
+ * central directory. */
long long directoryStartOffset,
/* The overall file offset of the start of the
* central directory. */
@@ -3806,7 +3817,7 @@
ZipWriteInt(start, end, buf + ZIP_CENTRAL_DIRSIZE_OFFS,
suffixStartOffset - directoryStartOffset);
ZipWriteInt(start, end, buf + ZIP_CENTRAL_DIRSTART_OFFS,
- directoryStartOffset);
+ directoryStartOffset - dataStartOffset);
ZipWriteShort(start, end, buf + ZIP_CENTRAL_COMMENTLEN_OFFS, 0);
}