1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
--- zip-2.31/unix/zipup.h.4GB 2005-01-29 07:47:58.000000000 +0100
+++ zip-2.31/unix/zipup.h 2005-11-10 13:18:02.990593904 +0100
@@ -6,13 +6,19 @@
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
+#include <features.h>
+#include <fcntl.h>
#ifndef O_RDONLY
# define O_RDONLY 0
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
-#define fhow (O_RDONLY|O_BINARY)
+#ifdef _LARGEFILE64_SOURCE
+#define fhow (O_RDONLY | O_LARGEFILE)
+#else
+#define fhow O_RDONLY
+#endif
#define fbad (-1)
typedef int ftype;
#define zopen(n,p) open(n,p)
--- zip-2.31/unix/unix.c.4GB 2005-02-11 03:35:02.000000000 +0100
+++ zip-2.31/unix/unix.c 2005-11-10 13:24:19.573344624 +0100
@@ -113,7 +113,11 @@
char *e; /* pointer to name from readd() */
int m; /* matched flag */
char *p; /* path for recursion */
+#ifdef _LARGEFILE64_SOURCE
+ struct stat64 s; /* result of stat() */
+#else
struct stat s; /* result of stat() */
+#endif
struct zlist far *z; /* steps through zfiles list */
if (strcmp(n, "-") == 0) /* if compressing stdin */
@@ -202,6 +206,15 @@
} /* (s.st_mode & S_IFDIR) */
else
zipwarn("ignoring special file: ", n);
+
+ /* Zip uses negative error codes (IIRC, to -3). Make sure file size
+ doesn't collide with error values. 2^32 - 8193 should be plenty until
+ info-zip supports zip64. */
+ if (s.st_size > MAX_ZIP_SIZE) {
+ zipwarn("file too large: ", a);
+ return ZE_MISS;
+ }
+
return ZE_OK;
}
@@ -321,7 +334,12 @@
If f is "-", use standard input as the file. If f is a device, return
a file size of -1 */
{
- struct stat s; /* results of stat() */
+#ifdef _LARGEFILE64_SOURCE
+ struct stat64 s; /* results of stat() */
+#else
+ struct stat s;
+#endif
+
/* converted to pointer from using FNMAX - 11/8/04 EG */
char *name;
int len = strlen(f);
@@ -343,7 +361,11 @@
name[len - 1] = '\0';
/* not all systems allow stat'ing a file with / appended */
if (strcmp(f, "-") == 0) {
+#ifdef _LARGEFILE64_SOURCE
+ if (fstat64(fileno(stdin), &s) != 0) {
+#else
if (fstat(fileno(stdin), &s) != 0) {
+#endif
free(name);
error("fstat(stdin)");
}
@@ -422,7 +444,11 @@
/* store full data in local header but just modification time stamp info
in central header */
{
+#ifdef _LARGEFILE64_SOURCE
+ struct stat64 s;
+#else
struct stat s;
+#endif
char *name;
int len = strlen(z->name);
--- zip-2.31/unix/configure.4GB 2004-12-05 09:51:18.000000000 +0100
+++ zip-2.31/unix/configure 2005-11-10 13:12:47.010630160 +0100
@@ -12,7 +12,7 @@
trap "rm -f conftest* core a.out; exit 1" 1 2 3 15
CC=${1-cc}
-CFLAGS=${2-"-O2 -I. -DUNIX"}
+CFLAGS=${2-"-O2 -I. -DUNIX -g -D_LARGEFILE64_SOURCE"}
LFLAGS1=""
LN="ln -s"
--- zip-2.31/fileio.c.4GB 2005-11-10 12:59:43.000000000 +0100
+++ zip-2.31/fileio.c 2005-11-10 13:07:13.190378552 +0100
@@ -599,7 +599,11 @@
this will be done by setfileattr() later.
*/
{
+#ifdef _LARGEFILE64_SOURCE
+ struct stat64 t; /* results of stat64() */
+#else
struct stat t; /* results of stat() */
+#endif
#if defined(CMS_MVS)
/* cmsmvs.h defines FOPW_TEMP as memory(hiperspace). Since memory is
* lost at end of run, always do copy instead of rename.
@@ -698,8 +702,11 @@
return _dos_files(&buf, f, 0xff) < 0 ? 0x20 : buf.atr;
#else
+#ifdef _LARGEFILE64_SOURCE
+ struct stat64 s;
+#else
struct stat s;
-
+#endif
return SSTAT(f, &s) == 0 ? (int) s.st_mode : 0;
#endif
}
@@ -920,3 +927,108 @@
}
#endif /* NO_RENAME */
+
+/*
+ Wrapper functions for fopen/fseek/ftell for >2GB files.
+
+ So, what we do here is add support for 4GB seeks. More appropriately,
+ 2^32 - 8193 bytes. This is tailored to the way zip uses fseek; it never
+ seeks backwards more than 8192 bytes.
+ */
+#ifdef _LARGEFILE64_SOURCE
+FILE *
+lfopen(const char *path, const char *mode)
+{
+ int fd;
+ FILE *f;
+ int flags;
+ int x;
+ char prev;
+
+ if (!path || !mode | !strlen(mode))
+ return NULL;
+
+ for (x = 0; x < strlen(mode); x++) {
+ switch (mode[x]) {
+ case 'r':
+ flags = O_RDONLY | O_LARGEFILE;
+ break;
+ case 'w':
+ flags = O_WRONLY | O_LARGEFILE | O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ flags = O_RDWR | O_LARGEFILE;
+ break;
+ case 'b': /* b has no effect */
+ continue;
+ case '+':
+ if (prev == 'r') {
+ flags = O_RDWR | O_LARGEFILE;
+ } else if (prev == 'w') {
+ flags = O_RDWR | O_LARGEFILE | O_CREAT |
+ O_TRUNC;
+ } else if (prev == 'a') {
+ flags = O_RDWR | O_LARGEFILE | O_CREAT;
+ } else
+ return NULL;
+ break;
+ }
+ prev = mode[x];
+ }
+
+ fd = open(path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd == -1)
+ return NULL;
+
+ f = fdopen(fd, mode);
+ return f;
+}
+
+int
+lfseek(FILE *f, ulg pos, int whence)
+{
+ struct stat64 sb;
+ ulg o, delta;
+ int ret;
+
+ /* Hurts performance */
+ fflush(f);
+
+ if (pos <= MAX_ZIP_SIZE) {
+ return (lseek64(fileno(f), pos, whence) == (off64_t)-1);
+ }
+
+ delta = ~((off64_t)pos - 1);
+ if (whence == SEEK_CUR) {
+ o = lseek64(fileno(f), 0, SEEK_CUR);
+ if (o < delta)
+ return -1;
+
+ o -= delta;
+ return (lseek64(fileno(f), o, SEEK_SET) == (off64_t)-1);
+ }
+
+ if (whence == SEEK_END) {
+ fstat64(fileno(f), &sb);
+
+ if ((ulg)sb.st_size < delta)
+ return -1;
+
+ o = (off64_t)((sb.st_size) - delta);
+ return (lseek64(fileno(f), o, SEEK_SET) == (off64_t)-1);
+ }
+
+ return -1;
+}
+
+
+ulg
+lftell(FILE *f)
+{
+ /* Hurts performance */
+ fflush(f);
+ return (ulg)lseek64(fileno(f), 0, SEEK_CUR);
+}
+
+#endif /* _LARGEFILE64_SOURCE */
+
--- zip-2.31/zip.h.4GB 2005-11-10 12:59:43.000000000 +0100
+++ zip-2.31/zip.h 2005-11-10 13:18:57.653283912 +0100
@@ -236,6 +236,7 @@
#define DOSTIME_MINIMUM ((ulg)0x00210000L)
#define DOSTIME_2038_01_18 ((ulg)0x74320000L)
+#define MAX_ZIP_SIZE 0xffffdffe /* Max archive / archive member size */
/* Public globals */
extern uch upper[256]; /* Country dependent case map table */
@@ -411,6 +412,11 @@
int putcentral OF((struct zlist far *, FILE *));
int putend OF((int, ulg, ulg, extent, char *, FILE *));
int zipcopy OF((struct zlist far *, FILE *, FILE *));
+#ifdef _LARGEFILE64_SOURCE
+int lfseek OF((FILE *, ulg, int));
+ulg lftell OF((FILE *));
+FILE *lfopen OF((const char *, const char *));
+#endif /* LF64 */
/* in fileio.c */
#ifndef UTIL
--- zip-2.31/tailor.h.4GB 2005-03-04 08:45:26.000000000 +0100
+++ zip-2.31/tailor.h 2005-11-10 13:11:18.909023640 +0100
@@ -368,12 +368,27 @@
# define DYN_ALLOC
#endif
+#ifdef _LARGEFILE64_SOURCE
+#define fopen lfopen
+#define fseek lfseek
+#define ftell lftell
+#endif /* LF64 */
+
#ifndef SSTAT
-# define SSTAT stat
+# ifdef _LARGEFILE64_SOURCE
+# define SSTAT stat64
+# else
+# define SSTAT stat
+# endif /* LF64 */
#endif
#ifdef S_IFLNK
-# define LSTAT lstat
-# define LSSTAT(n, s) (linkput ? lstat((n), (s)) : SSTAT((n), (s)))
+# ifdef _LARGEFILE64_SOURCE
+# define LSTAT lstat64
+# define LSSTAT(n, s) (linkput ? lstat64((n), (s)) : SSTAT((n), (s)))
+# else
+# define LSTAT lstat64
+# define LSSTAT(n, s) (linkput ? lstat64((n), (s)) : SSTAT((n), (s)))
+# endif /* LF64 */
#else
# define LSTAT SSTAT
# define LSSTAT SSTAT
|