diff --git a/libc/log/startfatal.c b/libc/log/startfatal.c index b52cec74d..7192b3915 100644 --- a/libc/log/startfatal.c +++ b/libc/log/startfatal.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/errno.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/safemacros.internal.h" #include "libc/log/internal.h" -#include "libc/errno.h" #include "libc/thread/thread.h" /** @@ -30,8 +30,6 @@ relegated void __start_fatal(const char *file, int line) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); __restore_tty(); - kprintf("%r%serror%s:%s:%d:%s%s: ", !__nocolor ? "\e[J\e[30;101m" : "", - !__nocolor ? "\e[94;49m" : "", file, line, - firstnonnull(program_invocation_short_name, "unknown"), - !__nocolor ? "\e[0m" : ""); + kprintf("%r%serror%s:%s:%d%s: ", !__nocolor ? "\e[J\e[30;101m" : "", + !__nocolor ? "\e[94;49m" : "", file, line, !__nocolor ? "\e[0m" : ""); } diff --git a/libc/str/getzipcfilecompressedsize.c b/libc/str/getzipcfilecompressedsize.c index 816bbae85..aaa7c86da 100644 --- a/libc/str/getzipcfilecompressedsize.c +++ b/libc/str/getzipcfilecompressedsize.c @@ -21,17 +21,18 @@ /** * Returns compressed size in bytes from zip central directory header. */ -uint64_t GetZipCfileCompressedSize(const uint8_t *z) { - uint64_t x; - const uint8_t *p, *pe; - if ((x = ZIP_CFILE_COMPRESSEDSIZE(z)) == 0xFFFFFFFF) { - for (p = ZIP_CFILE_EXTRA(z), pe = p + ZIP_CFILE_EXTRASIZE(z); p < pe; - p += ZIP_EXTRA_SIZE(p)) { - if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 && - 8 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { - return READ64LE(ZIP_EXTRA_CONTENT(p) + 8); +int64_t GetZipCfileCompressedSize(const uint8_t *z) { + if (ZIP_CFILE_COMPRESSEDSIZE(z) != 0xFFFFFFFFu) { + return ZIP_CFILE_COMPRESSEDSIZE(z); + } + const uint8_t *p = ZIP_CFILE_EXTRA(z); + const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z); + for (; p < pe; p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) { + if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) { + return READ64LE(ZIP_EXTRA_CONTENT(p)); } } } - return x; + return -1; } diff --git a/libc/str/getzipcfileoffset.c b/libc/str/getzipcfileoffset.c index 53e070e7d..3ce6c6d3e 100644 --- a/libc/str/getzipcfileoffset.c +++ b/libc/str/getzipcfileoffset.c @@ -21,17 +21,25 @@ /** * Returns offset of local file header. */ -uint64_t GetZipCfileOffset(const uint8_t *z) { - uint64_t x; - const uint8_t *p, *pe; - if ((x = ZIP_CFILE_OFFSET(z)) == 0xFFFFFFFF) { - for (p = ZIP_CFILE_EXTRA(z), pe = p + ZIP_CFILE_EXTRASIZE(z); p < pe; - p += ZIP_EXTRA_SIZE(p)) { - if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 && - 16 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { - return READ64LE(ZIP_EXTRA_CONTENT(p) + 16); +int64_t GetZipCfileOffset(const uint8_t *z) { + if (ZIP_CFILE_OFFSET(z) != 0xFFFFFFFFu) { + return ZIP_CFILE_OFFSET(z); + } + const uint8_t *p = ZIP_CFILE_EXTRA(z); + const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z); + for (; p < pe; p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) { + int offset = 0; + if (ZIP_CFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) { + offset += 8; + } + if (ZIP_CFILE_UNCOMPRESSEDSIZE(z) == 0xFFFFFFFFu) { + offset += 8; + } + if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { + return READ64LE(ZIP_EXTRA_CONTENT(p) + offset); } } } - return x; + return -1; } diff --git a/libc/str/getzipcfileuncompressedsize.c b/libc/str/getzipcfileuncompressedsize.c index afdab1c2d..95cd0f333 100644 --- a/libc/str/getzipcfileuncompressedsize.c +++ b/libc/str/getzipcfileuncompressedsize.c @@ -21,17 +21,22 @@ /** * Returns uncompressed size in bytes from zip central directory header. */ -uint64_t GetZipCfileUncompressedSize(const uint8_t *z) { - uint64_t x; - const uint8_t *p, *pe; - if ((x = ZIP_CFILE_UNCOMPRESSEDSIZE(z)) == 0xFFFFFFFF) { - for (p = ZIP_CFILE_EXTRA(z), pe = p + ZIP_CFILE_EXTRASIZE(z); p < pe; - p += ZIP_EXTRA_SIZE(p)) { - if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 && - 0 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { - return READ64LE(ZIP_EXTRA_CONTENT(p) + 0); +int64_t GetZipCfileUncompressedSize(const uint8_t *z) { + if (ZIP_CFILE_UNCOMPRESSEDSIZE(z) != 0xFFFFFFFFu) { + return ZIP_CFILE_UNCOMPRESSEDSIZE(z); + } + const uint8_t *p = ZIP_CFILE_EXTRA(z); + const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z); + for (; p < pe; p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) { + int offset = 0; + if (ZIP_CFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) { + offset += 8; + } + if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { + return READ64LE(ZIP_EXTRA_CONTENT(p) + offset); } } } - return x; + return -1; } diff --git a/libc/str/getziplfilecompressedsize.c b/libc/str/getziplfilecompressedsize.c index bb53119ea..a170c6612 100644 --- a/libc/str/getziplfilecompressedsize.c +++ b/libc/str/getziplfilecompressedsize.c @@ -21,17 +21,18 @@ /** * Returns compressed size in bytes from zip local file header. */ -uint64_t GetZipLfileCompressedSize(const uint8_t *z) { - uint64_t x; - const uint8_t *p, *pe; - if ((x = ZIP_LFILE_COMPRESSEDSIZE(z)) == 0xFFFFFFFF) { - for (p = ZIP_LFILE_EXTRA(z), pe = p + ZIP_LFILE_EXTRASIZE(z); p < pe; - p += ZIP_EXTRA_SIZE(p)) { - if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 && - 8 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { - return READ64LE(ZIP_EXTRA_CONTENT(p) + 8); +int64_t GetZipLfileCompressedSize(const uint8_t *z) { + if (ZIP_LFILE_COMPRESSEDSIZE(z) != 0xFFFFFFFFu) { + return ZIP_LFILE_COMPRESSEDSIZE(z); + } + const uint8_t *p = ZIP_LFILE_EXTRA(z); + const uint8_t *pe = p + ZIP_LFILE_EXTRASIZE(z); + for (; p < pe; p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) { + if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) { + return READ64LE(ZIP_EXTRA_CONTENT(p)); } } } - return x; + return -1; } diff --git a/libc/str/getziplfileuncompressedsize.c b/libc/str/getziplfileuncompressedsize.c index be3295ed2..2e245aba5 100644 --- a/libc/str/getziplfileuncompressedsize.c +++ b/libc/str/getziplfileuncompressedsize.c @@ -21,18 +21,22 @@ /** * Returns uncompressed size in bytes from zip local file header. */ -uint64_t GetZipLfileUncompressedSize(const uint8_t *z) { - uint64_t x; - const uint8_t *p, *pe; - x = ZIP_LFILE_UNCOMPRESSEDSIZE(z); - if (x == 0xFFFFFFFF) { - for (p = ZIP_LFILE_EXTRA(z), pe = p + ZIP_LFILE_EXTRASIZE(z); p < pe; - p += ZIP_EXTRA_SIZE(p)) { - if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64 && - 0 + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { - return READ64LE(ZIP_EXTRA_CONTENT(p) + 0); +int64_t GetZipLfileUncompressedSize(const uint8_t *z) { + if (ZIP_LFILE_UNCOMPRESSEDSIZE(z) != 0xFFFFFFFFu) { + return ZIP_LFILE_UNCOMPRESSEDSIZE(z); + } + const uint8_t *p = ZIP_LFILE_EXTRA(z); + const uint8_t *pe = p + ZIP_LFILE_EXTRASIZE(z); + for (; p < pe; p += ZIP_EXTRA_SIZE(p)) { + if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) { + int offset = 0; + if (ZIP_LFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) { + offset += 8; + } + if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) { + return READ64LE(ZIP_EXTRA_CONTENT(p) + offset); } } } - return x; + return -1; } diff --git a/libc/zip.internal.h b/libc/zip.internal.h index 8893d384c..245add37a 100644 --- a/libc/zip.internal.h +++ b/libc/zip.internal.h @@ -102,6 +102,7 @@ #define kZipLfileHdrMagic ZM_(0x04034b50) /* PK♥♦ "PK\3\4" */ #define kZipLfileHdrMinSize 30 +#define kZipLfileOffsetVersionNeeded 4 #define kZipLfileOffsetGeneralflag 6 #define kZipLfileOffsetCompressionmethod 8 #define kZipLfileOffsetLastmodifiedtime 10 @@ -228,11 +229,11 @@ uint64_t GetZipCdirRecords(const uint8_t *); const void *GetZipCdirComment(const uint8_t *); uint64_t GetZipCdirSize(const uint8_t *); uint64_t GetZipCdirCommentSize(const uint8_t *); -uint64_t GetZipCfileUncompressedSize(const uint8_t *); -uint64_t GetZipCfileCompressedSize(const uint8_t *); -uint64_t GetZipCfileOffset(const uint8_t *); -uint64_t GetZipLfileUncompressedSize(const uint8_t *); -uint64_t GetZipLfileCompressedSize(const uint8_t *); +int64_t GetZipCfileCompressedSize(const uint8_t *); +int64_t GetZipCfileUncompressedSize(const uint8_t *); +int64_t GetZipCfileOffset(const uint8_t *); +int64_t GetZipLfileCompressedSize(const uint8_t *); +int64_t GetZipLfileUncompressedSize(const uint8_t *); void GetZipCfileTimestamps(const uint8_t *, struct timespec *, struct timespec *, struct timespec *, int); diff --git a/tool/build/apelink.c b/tool/build/apelink.c index 5807ac107..4358d0ed1 100644 --- a/tool/build/apelink.c +++ b/tool/build/apelink.c @@ -676,7 +676,7 @@ static void LoadSymbols(Elf64_Ehdr *e, Elf64_Off size, const char *path) { WRITE32LE(cfile, kZipCfileHdrMagic); cfile[4] = kZipCosmopolitanVersion; cfile[5] = kZipOsUnix; - cfile[6] = kZipEra1993; + cfile[6] = kZipEra2001; WRITE16LE(cfile + kZipCfileOffsetCompressionmethod, kZipCompressionDeflate); WRITE16LE(cfile + kZipCfileOffsetLastmodifieddate, DOS_DATE(2023, 7, 29)); WRITE16LE(cfile + kZipCfileOffsetLastmodifiedtime, DOS_TIME(0, 0, 0)); @@ -690,8 +690,8 @@ static void LoadSymbols(Elf64_Ehdr *e, Elf64_Off size, const char *path) { unsigned char *lfile = Malloc(lfile_size); bzero(lfile, lfile_size); WRITE32LE(lfile, kZipLfileHdrMagic); - cfile[4] = kZipEra1993; - cfile[5] = kZipOsDos; + WRITE16LE(lfile + kZipLfileOffsetVersionNeeded, kZipEra2001); + WRITE16LE(lfile + kZipLfileOffsetGeneralflag, kZipGflagUtf8); WRITE16LE(lfile + kZipLfileOffsetCompressionmethod, kZipCompressionDeflate); WRITE16LE(lfile + kZipLfileOffsetLastmodifieddate, DOS_DATE(2023, 7, 29)); WRITE16LE(lfile + kZipLfileOffsetLastmodifiedtime, DOS_TIME(0, 0, 0)); diff --git a/tool/net/redbean.c b/tool/net/redbean.c index c08e0de07..0179ce0dc 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -263,7 +263,7 @@ struct Strings { struct String { size_t n; const char *s; - } * p; + } *p; }; struct DeflateGenerator { @@ -291,7 +291,7 @@ static struct Servers { struct Server { int fd; struct sockaddr_in addr; - } * p; + } *p; } servers; static struct Freelist { @@ -305,7 +305,7 @@ static struct Unmaplist { int f; void *p; size_t n; - } * p; + } *p; } unmaplist; static struct Psks { @@ -316,7 +316,7 @@ static struct Psks { char *identity; size_t identity_len; char *s; - } * p; + } *p; } psks; static struct Suites { @@ -335,7 +335,7 @@ static struct Redirects { int code; struct String path; struct String location; - } * p; + } *p; } redirects; static struct Assets { @@ -350,8 +350,8 @@ static struct Assets { struct File { struct String path; struct stat st; - } * file; - } * p; + } *file; + } *p; } assets; static struct TrustedIps { @@ -359,7 +359,7 @@ static struct TrustedIps { struct TrustedIp { uint32_t ip; uint32_t mask; - } * p; + } *p; } trustedips; struct TokenBucket { @@ -393,7 +393,7 @@ static struct Shared { #undef C } c; pthread_spinlock_t montermlock; -} * shared; +} *shared; static const char kCounterNames[] = #define C(x) #x "\0" @@ -3695,8 +3695,8 @@ static void StoreAsset(const char *path, size_t pathlen, const char *data, p = WRITE16LE(p, mtime); p = WRITE16LE(p, mdate); p = WRITE32LE(p, crc); - p = WRITE32LE(p, MIN(uselen, 0xffffffff)); - p = WRITE32LE(p, MIN(datalen, 0xffffffff)); + p = WRITE32LE(p, 0xffffffffu); + p = WRITE32LE(p, 0xffffffffu); p = WRITE16LE(p, pathlen); p = WRITE16LE(p, v[2].iov_len); v[1].iov_len = pathlen; @@ -3755,8 +3755,8 @@ static void StoreAsset(const char *path, size_t pathlen, const char *data, p = WRITE16LE(p, mtime); p = WRITE16LE(p, mdate); p = WRITE32LE(p, crc); - p = WRITE32LE(p, MIN(uselen, 0xffffffff)); - p = WRITE32LE(p, MIN(datalen, 0xffffffff)); + p = WRITE32LE(p, 0xffffffffu); + p = WRITE32LE(p, 0xffffffffu); p = WRITE16LE(p, pathlen); p = WRITE16LE(p, v[8].iov_len + v[9].iov_len); p = WRITE16LE(p, 0); @@ -3764,7 +3764,7 @@ static void StoreAsset(const char *path, size_t pathlen, const char *data, p = WRITE16LE(p, iattrs); p = WRITE16LE(p, dosmode); p = WRITE16LE(p, mode); - p = WRITE32LE(p, MIN(zsize, 0xffffffff)); + p = WRITE32LE(p, 0xffffffffu); v[7].iov_len = pathlen; v[7].iov_base = (void *)path; // zip64 end of central directory