35
unsigned char size[4];
36
unsigned char filename_length[2];
37
unsigned char extra_length[2];
38
+ unsigned char _end[1];
39
};
40
41
struct zip_dir_header {
56
unsigned char attr1[2];
57
unsigned char attr2[4];
58
unsigned char offset[4];
59
+ unsigned char _end[1];
60
};
61
62
struct zip_dir_trailer {
68
unsigned char size[4];
69
unsigned char offset[4];
70
unsigned char comment_length[2];
71
+ unsigned char _end[1];
72
};
73
74
+/*
75
+ * On ARM, padding is added at the end of the struct, so a simple
76
+ * sizeof(struct ...) reports two bytes more than the payload size
77
+ * we're interested in.
78
+ */
79
+#define ZIP_LOCAL_HEADER_SIZE offsetof(struct zip_local_header, _end)
80
+#define ZIP_DIR_HEADER_SIZE offsetof(struct zip_dir_header, _end)
81
+#define ZIP_DIR_TRAILER_SIZE offsetof(struct zip_dir_trailer, _end)
82
+
83
static void copy_le16(unsigned char *dest, unsigned int n)
84
{
85
dest[0] = 0xff & n;
223
}
224
225
/* make sure we have enough free space in the dictionary */
214
- direntsize = sizeof(struct zip_dir_header) + pathlen;
226
+ direntsize = ZIP_DIR_HEADER_SIZE + pathlen;
227
while (zip_dir_size < zip_dir_offset + direntsize) {
228
zip_dir_size += ZIP_DIRECTORY_MIN_SIZE;
229
zip_dir = xrealloc(zip_dir, zip_dir_size);
246
copy_le16(dirent.attr1, 0);
247
copy_le32(dirent.attr2, attr2);
248
copy_le32(dirent.offset, zip_offset);
237
- memcpy(zip_dir + zip_dir_offset, &dirent, sizeof(struct zip_dir_header));
238
- zip_dir_offset += sizeof(struct zip_dir_header);
249
+ memcpy(zip_dir + zip_dir_offset, &dirent, ZIP_DIR_HEADER_SIZE);
250
+ zip_dir_offset += ZIP_DIR_HEADER_SIZE;
251
memcpy(zip_dir + zip_dir_offset, path, pathlen);
252
zip_dir_offset += pathlen;
253
zip_dir_entries++;
263
copy_le32(header.size, uncompressed_size);
264
copy_le16(header.filename_length, pathlen);
265
copy_le16(header.extra_length, 0);
254
- write_or_die(1, &header, sizeof(struct zip_local_header));
255
- zip_offset += sizeof(struct zip_local_header);
266
+ write_or_die(1, &header, ZIP_LOCAL_HEADER_SIZE);
267
+ zip_offset += ZIP_LOCAL_HEADER_SIZE;
268
write_or_die(1, path, pathlen);
269
zip_offset += pathlen;
270
if (compressed_size > 0) {
294
copy_le16(trailer.comment_length, sha1 ? 40 : 0);
295
296
write_or_die(1, zip_dir, zip_dir_offset);
285
- write_or_die(1, &trailer, sizeof(struct zip_dir_trailer));
297
+ write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);
298
if (sha1)
299
write_or_die(1, sha1_to_hex(sha1), 40);
300
}