@@ -63,6 +63,13 @@ static int DetermineVersionNeededToExtract(int method) {
63
63
}
64
64
}
65
65
66
+ static int NormalizeMode (int mode ) {
67
+ int res = mode & S_IFMT ;
68
+ if (mode & 0111 )
69
+ res |= 0111 ;
70
+ return res | 0644 ;
71
+ }
72
+
66
73
static unsigned char * EmitZipLfileHdr (unsigned char * p , const void * name ,
67
74
size_t namesize , uint32_t crc ,
68
75
uint8_t era , uint16_t gflags ,
@@ -87,10 +94,10 @@ static unsigned char *EmitZipLfileHdr(unsigned char *p, const void *name,
87
94
static void EmitZipCdirHdr (unsigned char * p , const void * name , size_t namesize ,
88
95
uint32_t crc , uint8_t era , uint16_t gflags ,
89
96
uint16_t method , uint16_t mtime , uint16_t mdate ,
90
- uint16_t iattrs , uint16_t dosmode , uint16_t unixmode ,
91
- size_t compsize , size_t uncompsize ,
92
- size_t commentsize , struct timespec mtim ,
93
- struct timespec atim , struct timespec ctim ) {
97
+ uint16_t iattrs , uint16_t unixmode , size_t compsize ,
98
+ size_t uncompsize , size_t commentsize ,
99
+ struct timespec mtim , struct timespec atim ,
100
+ struct timespec ctim ) {
94
101
uint64_t mt , at , ct ;
95
102
p = WRITE32LE (p , kZipCfileHdrMagic );
96
103
* p ++ = kZipCosmopolitanVersion ;
@@ -111,8 +118,8 @@ static void EmitZipCdirHdr(unsigned char *p, const void *name, size_t namesize,
111
118
p = WRITE16LE (p , commentsize );
112
119
p = WRITE16LE (p , 0 ); /* disk */
113
120
p = WRITE16LE (p , iattrs );
114
- p = WRITE16LE (p , dosmode );
115
- p = WRITE16LE (p , unixmode );
121
+ p = WRITE16LE (p , 0 );
122
+ p = WRITE16LE (p , NormalizeMode ( unixmode ) );
116
123
p = WRITE32LE (p , 0 ); /* RELOCATE ME (kZipCfileOffsetOffset) */
117
124
/* 46 */
118
125
memcpy (p , name , namesize );
@@ -142,8 +149,8 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname,
142
149
uint32_t crc ;
143
150
unsigned char * lfile , * cfile ;
144
151
struct ElfWriterSymRef lfilesym ;
152
+ uint16_t method , gflags , mtime , mdate , iattrs ;
145
153
size_t lfilehdrsize , uncompsize , compsize , commentsize ;
146
- uint16_t method , gflags , mtime , mdate , iattrs , dosmode ;
147
154
148
155
CHECK_NE (0 , mtim .tv_sec );
149
156
@@ -168,7 +175,6 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname,
168
175
if (S_ISREG (mode ) && istext (data , size )) {
169
176
iattrs |= kZipIattrText ;
170
177
}
171
- dosmode = !(mode & 0200 ) ? kNtFileAttributeReadonly : 0 ;
172
178
method = ShouldCompress (name , namesize , data , size , nocompress )
173
179
? kZipCompressionDeflate
174
180
: kZipCompressionNone ;
@@ -215,8 +221,8 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname,
215
221
elfwriter_startsection (elf , ".zip.cdir" , SHT_PROGBITS , 0 );
216
222
EmitZipCdirHdr (
217
223
(cfile = elfwriter_reserve (elf , ZIP_CFILE_HDR_SIZE + namesize )), name ,
218
- namesize , crc , era , gflags , method , mtime , mdate , iattrs , dosmode , mode ,
219
- compsize , uncompsize , commentsize , mtim , atim , ctim );
224
+ namesize , crc , era , gflags , method , mtime , mdate , iattrs , mode , compsize ,
225
+ uncompsize , commentsize , mtim , atim , ctim );
220
226
elfwriter_appendsym (elf , gc (xasprintf ("%s%s" , "zip+cdir:" , name )),
221
227
ELF64_ST_INFO (STB_LOCAL , STT_OBJECT ), STV_DEFAULT , 0 ,
222
228
ZIP_CFILE_HDR_SIZE + namesize );
0 commit comments