misc/libphysfs/archiver_zip.c
author nemo
Thu, 17 May 2018 20:04:07 -0400
branch0.9.24
changeset 13393 ae5d6448c5be
parent 12452 e18cfe90e4e2
permissions -rw-r--r--
Make wrapping a lua and its sidecar actually work.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     1
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     2
 * ZIP support routines for PhysicsFS.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     3
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     5
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon, with some peeking at "unzip.c"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     7
 *   by Gilles Vollant.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     8
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     9
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    10
#define __PHYSICSFS_INTERNAL__
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    11
#include "physfs_internal.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    12
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    13
#if PHYSFS_SUPPORTS_ZIP
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    14
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    15
#include <errno.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    16
#include <time.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    17
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    18
#include "physfs_miniz.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    19
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    20
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    21
 * A buffer of ZIP_READBUFSIZE is allocated for each compressed file opened,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    22
 *  and is freed when you close the file; compressed data is read into
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    23
 *  this buffer, and then is decompressed into the buffer passed to
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    24
 *  PHYSFS_read().
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    25
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    26
 * Uncompressed entries in a zipfile do not allocate this buffer; they just
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    27
 *  read data directly into the buffer passed to PHYSFS_read().
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    28
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    29
 * Depending on your speed and memory requirements, you should tweak this
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    30
 *  value.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    32
#define ZIP_READBUFSIZE   (16 * 1024)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    33
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    35
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    36
 * Entries are "unresolved" until they are first opened. At that time,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    37
 *  local file headers parsed/validated, data offsets will be updated to look
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    38
 *  at the actual file data instead of the header, and symlinks will be
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    39
 *  followed and optimized. This means that we don't seek and read around the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    40
 *  archive until forced to do so, and after the first time, we had to do
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    41
 *  less reading and parsing, which is very CD-ROM friendly.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    42
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    43
typedef enum
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    44
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    45
    ZIP_UNRESOLVED_FILE,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    46
    ZIP_UNRESOLVED_SYMLINK,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    47
    ZIP_RESOLVING,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
    ZIP_RESOLVED,
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    49
    ZIP_DIRECTORY,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
    ZIP_BROKEN_FILE,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
    ZIP_BROKEN_SYMLINK
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
} ZipResolveType;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    53
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    54
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    55
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    56
 * One ZIPentry is kept for each file in an open ZIP archive.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    57
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    58
typedef struct _ZIPentry
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    59
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
    char *name;                         /* Name of file in archive        */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    61
    struct _ZIPentry *symlink;          /* NULL or file we symlink to     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    62
    ZipResolveType resolved;            /* Have we resolved file/symlink? */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    63
    PHYSFS_uint64 offset;               /* offset of data in archive      */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
    PHYSFS_uint16 version;              /* version made by                */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    65
    PHYSFS_uint16 version_needed;       /* version needed to extract      */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    66
    PHYSFS_uint16 general_bits;         /* general purpose bits           */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    67
    PHYSFS_uint16 compression_method;   /* compression method             */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    68
    PHYSFS_uint32 crc;                  /* crc-32                         */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    69
    PHYSFS_uint64 compressed_size;      /* compressed size                */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    70
    PHYSFS_uint64 uncompressed_size;    /* uncompressed size              */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    71
    PHYSFS_sint64 last_mod_time;        /* last file mod time             */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    72
    PHYSFS_uint32 dos_mod_time;         /* original MS-DOS style mod time */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    73
    struct _ZIPentry *hashnext;         /* next item in this hash bucket  */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    74
    struct _ZIPentry *children;         /* linked list of kids, if dir    */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    75
    struct _ZIPentry *sibling;          /* next item in same dir          */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    76
} ZIPentry;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    77
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    78
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    79
 * One ZIPinfo is kept for each open ZIP archive.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    80
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    81
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    82
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    83
    PHYSFS_Io *io;            /* the i/o interface for this archive.    */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    84
    ZIPentry root;            /* root of directory tree.                */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    85
    ZIPentry **hash;          /* all entries hashed for fast lookup.    */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    86
    size_t hashBuckets;       /* number of buckets in hash.             */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    87
    int zip64;                /* non-zero if this is a Zip64 archive.   */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
    88
    int has_crypto;           /* non-zero if any entry uses encryption. */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    89
} ZIPinfo;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    90
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    91
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    92
 * One ZIPfileinfo is kept for each open file in a ZIP archive.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    93
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    94
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    95
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    96
    ZIPentry *entry;                      /* Info on file.              */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    97
    PHYSFS_Io *io;                        /* physical file handle.      */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    98
    PHYSFS_uint32 compressed_position;    /* offset in compressed data. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    99
    PHYSFS_uint32 uncompressed_position;  /* tell() position.           */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   100
    PHYSFS_uint8 *buffer;                 /* decompression buffer.      */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   101
    PHYSFS_uint32 crypto_keys[3];         /* for "traditional" crypto.  */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   102
    PHYSFS_uint32 initial_crypto_keys[3]; /* for "traditional" crypto.  */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   103
    z_stream stream;                      /* zlib stream state.         */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   104
} ZIPfileinfo;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   105
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   106
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   107
/* Magic numbers... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   108
#define ZIP_LOCAL_FILE_SIG                          0x04034b50
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   109
#define ZIP_CENTRAL_DIR_SIG                         0x02014b50
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   110
#define ZIP_END_OF_CENTRAL_DIR_SIG                  0x06054b50
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   111
#define ZIP64_END_OF_CENTRAL_DIR_SIG                0x06064b50
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   112
#define ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIG  0x07064b50
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   113
#define ZIP64_EXTENDED_INFO_EXTRA_FIELD_SIG         0x0001
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   114
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   115
/* compression methods... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   116
#define COMPMETH_NONE 0
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   117
/* ...and others... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   118
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   119
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   120
#define UNIX_FILETYPE_MASK    0170000
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   121
#define UNIX_FILETYPE_SYMLINK 0120000
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   122
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   123
#define ZIP_GENERAL_BITS_TRADITIONAL_CRYPTO   (1 << 0)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   124
#define ZIP_GENERAL_BITS_IGNORE_LOCAL_HEADER  (1 << 3)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   125
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   126
/* support for "traditional" PKWARE encryption. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   127
static int zip_entry_is_tradional_crypto(const ZIPentry *entry)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   128
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   129
    return (entry->general_bits & ZIP_GENERAL_BITS_TRADITIONAL_CRYPTO) != 0;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   130
} /* zip_entry_is_traditional_crypto */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   131
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   132
static int zip_entry_ignore_local_header(const ZIPentry *entry)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   133
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   134
    return (entry->general_bits & ZIP_GENERAL_BITS_IGNORE_LOCAL_HEADER) != 0;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   135
} /* zip_entry_is_traditional_crypto */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   136
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   137
static PHYSFS_uint32 zip_crypto_crc32(const PHYSFS_uint32 crc, const PHYSFS_uint8 val)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   138
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   139
    int i;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   140
    PHYSFS_uint32 xorval = (crc ^ ((PHYSFS_uint32) val)) & 0xFF;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   141
    for (i = 0; i < 8; i++)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   142
        xorval = ((xorval & 1) ? (0xEDB88320 ^ (xorval >> 1)) : (xorval >> 1));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   143
    return xorval ^ (crc >> 8);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   144
} /* zip_crc32 */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   145
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   146
static void zip_update_crypto_keys(PHYSFS_uint32 *keys, const PHYSFS_uint8 val)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   147
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   148
    keys[0] = zip_crypto_crc32(keys[0], val);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   149
    keys[1] = keys[1] + (keys[0] & 0x000000FF);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   150
    keys[1] = (keys[1] * 134775813) + 1;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   151
    keys[2] = zip_crypto_crc32(keys[2], (PHYSFS_uint8) ((keys[1] >> 24) & 0xFF));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   152
} /* zip_update_crypto_keys */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   153
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   154
static PHYSFS_uint8 zip_decrypt_byte(const PHYSFS_uint32 *keys)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   155
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   156
    const PHYSFS_uint16 tmp = keys[2] | 2;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   157
    return (PHYSFS_uint8) ((tmp * (tmp ^ 1)) >> 8);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   158
} /* zip_decrypt_byte */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   159
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   160
static PHYSFS_sint64 zip_read_decrypt(ZIPfileinfo *finfo, void *buf, PHYSFS_uint64 len)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   161
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   162
    PHYSFS_Io *io = finfo->io;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   163
    const PHYSFS_sint64 br = io->read(io, buf, len);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   164
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   165
    /* Decompression the new data if necessary. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   166
    if (zip_entry_is_tradional_crypto(finfo->entry) && (br > 0))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   167
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   168
        PHYSFS_uint32 *keys = finfo->crypto_keys;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   169
        PHYSFS_uint8 *ptr = (PHYSFS_uint8 *) buf;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   170
        PHYSFS_sint64 i;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   171
        for (i = 0; i < br; i++, ptr++)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   172
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   173
            const PHYSFS_uint8 ch = *ptr ^ zip_decrypt_byte(keys);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   174
            zip_update_crypto_keys(keys, ch);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   175
            *ptr = ch;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   176
        } /* for */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   177
    } /* if  */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   178
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   179
    return br;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   180
} /* zip_read_decrypt */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   181
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   182
static int zip_prep_crypto_keys(ZIPfileinfo *finfo, const PHYSFS_uint8 *crypto_header, const PHYSFS_uint8 *password)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   183
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   184
    /* It doesn't appear to be documented in PKWare's APPNOTE.TXT, but you
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   185
       need to use a different byte in the header to verify the password
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   186
       if general purpose bit 3 is set. Discovered this from Info-Zip.
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   187
       That's what the (verifier) value is doing, below. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   188
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   189
    PHYSFS_uint32 *keys = finfo->crypto_keys;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   190
    const ZIPentry *entry = finfo->entry;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   191
    const int usedate = zip_entry_ignore_local_header(entry);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   192
    const PHYSFS_uint8 verifier = (PHYSFS_uint8) ((usedate ? (entry->dos_mod_time >> 8) : (entry->crc >> 24)) & 0xFF);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   193
    PHYSFS_uint8 finalbyte = 0;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   194
    int i = 0;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   195
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   196
    /* initialize vector with defaults, then password, then header. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   197
    keys[0] = 305419896;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   198
    keys[1] = 591751049;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   199
    keys[2] = 878082192;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   200
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   201
    while (*password)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   202
        zip_update_crypto_keys(keys, *(password++));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   203
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   204
    for (i = 0; i < 12; i++)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   205
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   206
        const PHYSFS_uint8 c = crypto_header[i] ^ zip_decrypt_byte(keys);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   207
        zip_update_crypto_keys(keys, c);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   208
        finalbyte = c;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   209
    } /* for */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   210
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   211
    /* you have a 1/256 chance of passing this test incorrectly. :/ */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   212
    if (finalbyte != verifier)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   213
        BAIL_MACRO(PHYSFS_ERR_BAD_PASSWORD, 0);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   214
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   215
    /* save the initial vector for seeking purposes. Not secure!! */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   216
    memcpy(finfo->initial_crypto_keys, finfo->crypto_keys, 12);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   217
    return 1;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   218
} /* zip_prep_crypto_keys */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   219
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   220
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   221
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   222
 * Bridge physfs allocation functions to zlib's format...
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   223
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   224
static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   225
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   226
    return ((PHYSFS_Allocator *) opaque)->Malloc(items * size);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   227
} /* zlibPhysfsAlloc */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   228
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   229
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   230
 * Bridge physfs allocation functions to zlib's format...
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   231
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   232
static void zlibPhysfsFree(voidpf opaque, voidpf address)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   233
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   234
    ((PHYSFS_Allocator *) opaque)->Free(address);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   235
} /* zlibPhysfsFree */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   236
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   237
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   238
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   239
 * Construct a new z_stream to a sane state.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   240
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   241
static void initializeZStream(z_stream *pstr)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   242
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   243
    memset(pstr, '\0', sizeof (z_stream));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   244
    pstr->zalloc = zlibPhysfsAlloc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   245
    pstr->zfree = zlibPhysfsFree;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   246
    pstr->opaque = &allocator;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   247
} /* initializeZStream */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   248
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   249
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   250
static PHYSFS_ErrorCode zlib_error_code(int rc)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   251
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   252
    switch (rc)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   253
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   254
        case Z_OK: return PHYSFS_ERR_OK;  /* not an error. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   255
        case Z_STREAM_END: return PHYSFS_ERR_OK; /* not an error. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   256
        case Z_ERRNO: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   257
        case Z_MEM_ERROR: return PHYSFS_ERR_OUT_OF_MEMORY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   258
        default: return PHYSFS_ERR_CORRUPT;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   259
    } /* switch */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   260
} /* zlib_error_string */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   261
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   262
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   263
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   264
 * Wrap all zlib calls in this, so the physfs error state is set appropriately.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   265
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   266
static int zlib_err(const int rc)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   267
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   268
    PHYSFS_setErrorCode(zlib_error_code(rc));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   269
    return rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   270
} /* zlib_err */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   271
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   272
/*
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   273
 * Hash a string for lookup an a ZIPinfo hashtable.
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   274
 */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   275
static inline PHYSFS_uint32 zip_hash_string(const ZIPinfo *info, const char *s)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   276
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   277
    return __PHYSFS_hashString(s, strlen(s)) % info->hashBuckets;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   278
} /* zip_hash_string */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   279
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   280
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   281
 * Read an unsigned 64-bit int and swap to native byte order.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   282
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   283
static int readui64(PHYSFS_Io *io, PHYSFS_uint64 *val)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   284
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   285
    PHYSFS_uint64 v;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   286
    BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   287
    *val = PHYSFS_swapULE64(v);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   288
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   289
} /* readui64 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   290
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   291
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   292
 * Read an unsigned 32-bit int and swap to native byte order.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   293
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   294
static int readui32(PHYSFS_Io *io, PHYSFS_uint32 *val)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   295
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   296
    PHYSFS_uint32 v;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   297
    BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   298
    *val = PHYSFS_swapULE32(v);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   299
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   300
} /* readui32 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   301
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   302
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   303
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   304
 * Read an unsigned 16-bit int and swap to native byte order.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   305
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   306
static int readui16(PHYSFS_Io *io, PHYSFS_uint16 *val)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   307
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   308
    PHYSFS_uint16 v;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   309
    BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   310
    *val = PHYSFS_swapULE16(v);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   311
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   312
} /* readui16 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   313
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   314
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   315
static PHYSFS_sint64 ZIP_read(PHYSFS_Io *_io, void *buf, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   316
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   317
    ZIPfileinfo *finfo = (ZIPfileinfo *) _io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   318
    ZIPentry *entry = finfo->entry;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   319
    PHYSFS_sint64 retval = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   320
    PHYSFS_sint64 maxread = (PHYSFS_sint64) len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   321
    PHYSFS_sint64 avail = entry->uncompressed_size -
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   322
                          finfo->uncompressed_position;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   323
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   324
    if (avail < maxread)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   325
        maxread = avail;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   326
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   327
    BAIL_IF_MACRO(maxread == 0, ERRPASS, 0);    /* quick rejection. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   328
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   329
    if (entry->compression_method == COMPMETH_NONE)
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   330
        retval = zip_read_decrypt(finfo, buf, maxread);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   331
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   332
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   333
        finfo->stream.next_out = buf;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   334
        finfo->stream.avail_out = (uInt) maxread;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   335
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   336
        while (retval < maxread)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   337
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   338
            PHYSFS_uint32 before = finfo->stream.total_out;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   339
            int rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   340
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   341
            if (finfo->stream.avail_in == 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   342
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   343
                PHYSFS_sint64 br;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   344
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   345
                br = entry->compressed_size - finfo->compressed_position;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   346
                if (br > 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   347
                {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   348
                    if (br > ZIP_READBUFSIZE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   349
                        br = ZIP_READBUFSIZE;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   350
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   351
                    br = zip_read_decrypt(finfo, finfo->buffer, (PHYSFS_uint64) br);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   352
                    if (br <= 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   353
                        break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   354
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   355
                    finfo->compressed_position += (PHYSFS_uint32) br;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   356
                    finfo->stream.next_in = finfo->buffer;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   357
                    finfo->stream.avail_in = (PHYSFS_uint32) br;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   358
                } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   359
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   360
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   361
            rc = zlib_err(inflate(&finfo->stream, Z_SYNC_FLUSH));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   362
            retval += (finfo->stream.total_out - before);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   363
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   364
            if (rc != Z_OK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   365
                break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   366
        } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   367
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   368
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   369
    if (retval > 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   370
        finfo->uncompressed_position += (PHYSFS_uint32) retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   371
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   372
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   373
} /* ZIP_read */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   374
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   375
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   376
static PHYSFS_sint64 ZIP_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   377
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   378
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   379
} /* ZIP_write */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   380
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   381
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   382
static PHYSFS_sint64 ZIP_tell(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   383
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   384
    return ((ZIPfileinfo *) io->opaque)->uncompressed_position;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   385
} /* ZIP_tell */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   386
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   387
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   388
static int ZIP_seek(PHYSFS_Io *_io, PHYSFS_uint64 offset)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   389
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   390
    ZIPfileinfo *finfo = (ZIPfileinfo *) _io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   391
    ZIPentry *entry = finfo->entry;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   392
    PHYSFS_Io *io = finfo->io;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   393
    const int encrypted = zip_entry_is_tradional_crypto(entry);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   394
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   395
    BAIL_IF_MACRO(offset > entry->uncompressed_size, PHYSFS_ERR_PAST_EOF, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   396
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   397
    if (!encrypted && (entry->compression_method == COMPMETH_NONE))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   398
    {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   399
        PHYSFS_sint64 newpos = offset + entry->offset;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   400
        BAIL_IF_MACRO(!io->seek(io, newpos), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   401
        finfo->uncompressed_position = (PHYSFS_uint32) offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   402
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   403
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   404
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   405
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   406
        /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   407
         * If seeking backwards, we need to redecode the file
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   408
         *  from the start and throw away the compressed bits until we hit
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   409
         *  the offset we need. If seeking forward, we still need to
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   410
         *  decode, but we don't rewind first.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   411
         */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   412
        if (offset < finfo->uncompressed_position)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   413
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   414
            /* we do a copy so state is sane if inflateInit2() fails. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   415
            z_stream str;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   416
            initializeZStream(&str);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   417
            if (zlib_err(inflateInit2(&str, -MAX_WBITS)) != Z_OK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   418
                return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   419
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   420
            if (!io->seek(io, entry->offset + (encrypted ? 12 : 0)))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   421
                return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   422
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   423
            inflateEnd(&finfo->stream);
12452
e18cfe90e4e2 fix physfs using inflateCopy() (not part of miniz)
sheepluva
parents: 12451
diff changeset
   424
            memcpy(&finfo->stream, &str, sizeof (z_stream));
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   425
            finfo->uncompressed_position = finfo->compressed_position = 0;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   426
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   427
            if (encrypted)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   428
                memcpy(finfo->crypto_keys, finfo->initial_crypto_keys, 12);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   429
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   430
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   431
        while (finfo->uncompressed_position != offset)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   432
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   433
            PHYSFS_uint8 buf[512];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   434
            PHYSFS_uint32 maxread;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   435
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   436
            maxread = (PHYSFS_uint32) (offset - finfo->uncompressed_position);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   437
            if (maxread > sizeof (buf))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   438
                maxread = sizeof (buf);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   439
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   440
            if (ZIP_read(_io, buf, maxread) != maxread)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   441
                return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   442
        } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   443
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   444
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   445
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   446
} /* ZIP_seek */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   447
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   448
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   449
static PHYSFS_sint64 ZIP_length(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   450
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   451
    const ZIPfileinfo *finfo = (ZIPfileinfo *) io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   452
    return (PHYSFS_sint64) finfo->entry->uncompressed_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   453
} /* ZIP_length */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   454
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   455
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   456
static PHYSFS_Io *zip_get_io(PHYSFS_Io *io, ZIPinfo *inf, ZIPentry *entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   457
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   458
static PHYSFS_Io *ZIP_duplicate(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   459
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   460
    ZIPfileinfo *origfinfo = (ZIPfileinfo *) io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   461
    PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   462
    ZIPfileinfo *finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   463
    GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   464
    GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   465
    memset(finfo, '\0', sizeof (*finfo));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   466
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   467
    finfo->entry = origfinfo->entry;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   468
    finfo->io = zip_get_io(origfinfo->io, NULL, finfo->entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   469
    GOTO_IF_MACRO(!finfo->io, ERRPASS, failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   470
13393
ae5d6448c5be Make wrapping a lua and its sidecar actually work.
nemo
parents: 12452
diff changeset
   471
	initializeZStream(&finfo->stream);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   472
    if (finfo->entry->compression_method != COMPMETH_NONE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   473
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   474
        finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   475
        GOTO_IF_MACRO(!finfo->buffer, PHYSFS_ERR_OUT_OF_MEMORY, failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   476
        if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   477
            goto failed;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   478
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   479
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   480
    memcpy(retval, io, sizeof (PHYSFS_Io));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   481
    retval->opaque = finfo;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   482
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   483
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   484
failed:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   485
    if (finfo != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   486
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   487
        if (finfo->io != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   488
            finfo->io->destroy(finfo->io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   489
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   490
        if (finfo->buffer != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   491
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   492
            allocator.Free(finfo->buffer);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   493
            inflateEnd(&finfo->stream);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   494
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   495
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   496
        allocator.Free(finfo);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   497
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   498
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   499
    if (retval != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   500
        allocator.Free(retval);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   501
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   502
    return NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   503
} /* ZIP_duplicate */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   504
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   505
static int ZIP_flush(PHYSFS_Io *io) { return 1;  /* no write support. */ }
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   506
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   507
static void ZIP_destroy(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   508
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   509
    ZIPfileinfo *finfo = (ZIPfileinfo *) io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   510
    finfo->io->destroy(finfo->io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   511
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   512
    if (finfo->entry->compression_method != COMPMETH_NONE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   513
        inflateEnd(&finfo->stream);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   514
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   515
    if (finfo->buffer != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   516
        allocator.Free(finfo->buffer);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   517
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   518
    allocator.Free(finfo);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   519
    allocator.Free(io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   520
} /* ZIP_destroy */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   521
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   522
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   523
static const PHYSFS_Io ZIP_Io =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   524
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   525
    CURRENT_PHYSFS_IO_API_VERSION, NULL,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   526
    ZIP_read,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   527
    ZIP_write,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   528
    ZIP_seek,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   529
    ZIP_tell,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   530
    ZIP_length,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   531
    ZIP_duplicate,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   532
    ZIP_flush,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   533
    ZIP_destroy
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   534
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   535
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   536
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   537
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   538
static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   539
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   540
    PHYSFS_uint8 buf[256];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   541
    PHYSFS_uint8 extra[4] = { 0, 0, 0, 0 };
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   542
    PHYSFS_sint32 i = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   543
    PHYSFS_sint64 filelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   544
    PHYSFS_sint64 filepos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   545
    PHYSFS_sint32 maxread;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   546
    PHYSFS_sint32 totalread = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   547
    int found = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   548
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   549
    filelen = io->length(io);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   550
    BAIL_IF_MACRO(filelen == -1, ERRPASS, -1);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   551
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   552
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   553
     * Jump to the end of the file and start reading backwards.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   554
     *  The last thing in the file is the zipfile comment, which is variable
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   555
     *  length, and the field that specifies its size is before it in the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   556
     *  file (argh!)...this means that we need to scan backwards until we
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   557
     *  hit the end-of-central-dir signature. We can then sanity check that
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   558
     *  the comment was as big as it should be to make sure we're in the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   559
     *  right place. The comment length field is 16 bits, so we can stop
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   560
     *  searching for that signature after a little more than 64k at most,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   561
     *  and call it a corrupted zipfile.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   562
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   563
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   564
    if (sizeof (buf) < filelen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   565
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   566
        filepos = filelen - sizeof (buf);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   567
        maxread = sizeof (buf);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   568
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   569
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   570
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   571
        filepos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   572
        maxread = (PHYSFS_uint32) filelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   573
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   574
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   575
    while ((totalread < filelen) && (totalread < 65557))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   576
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   577
        BAIL_IF_MACRO(!io->seek(io, filepos), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   578
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   579
        /* make sure we catch a signature between buffers. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   580
        if (totalread != 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   581
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   582
            if (!__PHYSFS_readAll(io, buf, maxread - 4))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   583
                return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   584
            memcpy(&buf[maxread - 4], &extra, sizeof (extra));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   585
            totalread += maxread - 4;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   586
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   587
        else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   588
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   589
            if (!__PHYSFS_readAll(io, buf, maxread))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   590
                return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   591
            totalread += maxread;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   592
        } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   593
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   594
        memcpy(&extra, buf, sizeof (extra));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   595
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   596
        for (i = maxread - 4; i > 0; i--)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   597
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   598
            if ((buf[i + 0] == 0x50) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   599
                (buf[i + 1] == 0x4B) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   600
                (buf[i + 2] == 0x05) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   601
                (buf[i + 3] == 0x06) )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   602
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   603
                found = 1;  /* that's the signature! */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   604
                break;  
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   605
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   606
        } /* for */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   607
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   608
        if (found)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   609
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   610
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   611
        filepos -= (maxread - 4);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   612
        if (filepos < 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   613
            filepos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   614
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   615
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   616
    BAIL_IF_MACRO(!found, PHYSFS_ERR_UNSUPPORTED, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   617
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   618
    if (len != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   619
        *len = filelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   620
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   621
    return (filepos + i);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   622
} /* zip_find_end_of_central_dir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   623
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   624
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   625
static int isZip(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   626
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   627
    PHYSFS_uint32 sig = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   628
    int retval = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   629
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   630
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   631
     * The first thing in a zip file might be the signature of the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   632
     *  first local file record, so it makes for a quick determination.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   633
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   634
    if (readui32(io, &sig))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   635
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   636
        retval = (sig == ZIP_LOCAL_FILE_SIG);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   637
        if (!retval)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   638
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   639
            /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   640
             * No sig...might be a ZIP with data at the start
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   641
             *  (a self-extracting executable, etc), so we'll have to do
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   642
             *  it the hard way...
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   643
             */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   644
            retval = (zip_find_end_of_central_dir(io, NULL) != -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   645
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   646
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   647
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   648
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   649
} /* isZip */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   650
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   651
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   652
/* Find the ZIPentry for a path in platform-independent notation. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   653
static ZIPentry *zip_find_entry(ZIPinfo *info, const char *path)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   654
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   655
    PHYSFS_uint32 hashval;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   656
    ZIPentry *prev = NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   657
    ZIPentry *retval;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   658
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   659
    if (*path == '\0')
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   660
        return &info->root;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   661
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   662
    hashval = zip_hash_string(info, path);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   663
    for (retval = info->hash[hashval]; retval; retval = retval->hashnext)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   664
    {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   665
        if (strcmp(retval->name, path) == 0)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   666
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   667
            if (prev != NULL)  /* move this to the front of the list */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   668
            {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   669
                prev->hashnext = retval->hashnext;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   670
                retval->hashnext = info->hash[hashval];
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   671
                info->hash[hashval] = retval;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   672
            } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   673
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   674
            return retval;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   675
        } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   676
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   677
        prev = retval;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   678
    } /* for */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   679
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   680
    BAIL_MACRO(PHYSFS_ERR_NOT_FOUND, NULL);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   681
} /* zip_find_entry */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   682
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   683
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   684
/* Convert paths from old, buggy DOS zippers... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   685
static void zip_convert_dos_path(ZIPentry *entry, char *path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   686
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   687
    PHYSFS_uint8 hosttype = (PHYSFS_uint8) ((entry->version >> 8) & 0xFF);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   688
    if (hosttype == 0)  /* FS_FAT_ */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   689
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   690
        while (*path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   691
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   692
            if (*path == '\\')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   693
                *path = '/';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   694
            path++;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   695
        } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   696
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   697
} /* zip_convert_dos_path */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   698
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   699
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   700
static void zip_expand_symlink_path(char *path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   701
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   702
    char *ptr = path;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   703
    char *prevptr = path;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   704
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   705
    while (1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   706
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   707
        ptr = strchr(ptr, '/');
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   708
        if (ptr == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   709
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   710
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   711
        if (*(ptr + 1) == '.')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   712
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   713
            if (*(ptr + 2) == '/')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   714
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   715
                /* current dir in middle of string: ditch it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   716
                memmove(ptr, ptr + 2, strlen(ptr + 2) + 1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   717
            } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   718
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   719
            else if (*(ptr + 2) == '\0')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   720
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   721
                /* current dir at end of string: ditch it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   722
                *ptr = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   723
            } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   724
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   725
            else if (*(ptr + 2) == '.')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   726
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   727
                if (*(ptr + 3) == '/')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   728
                {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   729
                    /* parent dir in middle: move back one, if possible. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   730
                    memmove(prevptr, ptr + 4, strlen(ptr + 4) + 1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   731
                    ptr = prevptr;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   732
                    while (prevptr != path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   733
                    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   734
                        prevptr--;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   735
                        if (*prevptr == '/')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   736
                        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   737
                            prevptr++;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   738
                            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   739
                        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   740
                    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   741
                } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   742
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   743
                if (*(ptr + 3) == '\0')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   744
                {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   745
                    /* parent dir at end: move back one, if possible. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   746
                    *prevptr = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   747
                } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   748
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   749
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   750
        else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   751
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   752
            prevptr = ptr;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   753
            ptr++;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   754
        } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   755
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   756
} /* zip_expand_symlink_path */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   757
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   758
/* (forward reference: zip_follow_symlink and zip_resolve call each other.) */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   759
static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   760
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   761
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   762
 * Look for the entry named by (path). If it exists, resolve it, and return
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   763
 *  a pointer to that entry. If it's another symlink, keep resolving until you
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   764
 *  hit a real file and then return a pointer to the final non-symlink entry.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   765
 *  If there's a problem, return NULL.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   766
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   767
static ZIPentry *zip_follow_symlink(PHYSFS_Io *io, ZIPinfo *info, char *path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   768
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   769
    ZIPentry *entry;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   770
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   771
    zip_expand_symlink_path(path);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   772
    entry = zip_find_entry(info, path);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   773
    if (entry != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   774
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   775
        if (!zip_resolve(io, info, entry))  /* recursive! */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   776
            entry = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   777
        else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   778
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   779
            if (entry->symlink != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   780
                entry = entry->symlink;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   781
        } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   782
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   783
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   784
    return entry;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   785
} /* zip_follow_symlink */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   786
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   787
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   788
static int zip_resolve_symlink(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   789
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   790
    const PHYSFS_uint64 size = entry->uncompressed_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   791
    char *path = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   792
    int rc = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   793
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   794
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   795
     * We've already parsed the local file header of the symlink at this
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   796
     *  point. Now we need to read the actual link from the file data and
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   797
     *  follow it.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   798
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   799
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   800
    BAIL_IF_MACRO(!io->seek(io, entry->offset), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   801
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   802
    path = (char *) __PHYSFS_smallAlloc(size + 1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   803
    BAIL_IF_MACRO(!path, PHYSFS_ERR_OUT_OF_MEMORY, 0);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   804
    
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   805
    if (entry->compression_method == COMPMETH_NONE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   806
        rc = __PHYSFS_readAll(io, path, size);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   807
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   808
    else  /* symlink target path is compressed... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   809
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   810
        z_stream stream;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   811
        const PHYSFS_uint64 complen = entry->compressed_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   812
        PHYSFS_uint8 *compressed = (PHYSFS_uint8*) __PHYSFS_smallAlloc(complen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   813
        if (compressed != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   814
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   815
            if (__PHYSFS_readAll(io, compressed, complen))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   816
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   817
                initializeZStream(&stream);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   818
                stream.next_in = compressed;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   819
                stream.avail_in = complen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   820
                stream.next_out = (unsigned char *) path;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   821
                stream.avail_out = size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   822
                if (zlib_err(inflateInit2(&stream, -MAX_WBITS)) == Z_OK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   823
                {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   824
                    rc = zlib_err(inflate(&stream, Z_FINISH));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   825
                    inflateEnd(&stream);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   826
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   827
                    /* both are acceptable outcomes... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   828
                    rc = ((rc == Z_OK) || (rc == Z_STREAM_END));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   829
                } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   830
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   831
            __PHYSFS_smallFree(compressed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   832
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   833
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   834
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   835
    if (rc)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   836
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   837
        path[entry->uncompressed_size] = '\0';    /* null-terminate it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   838
        zip_convert_dos_path(entry, path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   839
        entry->symlink = zip_follow_symlink(io, info, path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   840
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   841
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   842
    __PHYSFS_smallFree(path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   843
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   844
    return (entry->symlink != NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   845
} /* zip_resolve_symlink */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   846
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   847
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   848
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   849
 * Parse the local file header of an entry, and update entry->offset.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   850
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   851
static int zip_parse_local(PHYSFS_Io *io, ZIPentry *entry)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   852
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   853
    PHYSFS_uint32 ui32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   854
    PHYSFS_uint16 ui16;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   855
    PHYSFS_uint16 fnamelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   856
    PHYSFS_uint16 extralen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   857
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   858
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   859
     * crc and (un)compressed_size are always zero if this is a "JAR"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   860
     *  archive created with Sun's Java tools, apparently. We only
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   861
     *  consider this archive corrupted if those entries don't match and
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   862
     *  aren't zero. That seems to work well.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   863
     * We also ignore a mismatch if the value is 0xFFFFFFFF here, since it's
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   864
     *  possible that's a Zip64 thing.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   865
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   866
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   867
    /* !!! FIXME: apparently these are zero if general purpose bit 3 is set,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   868
       !!! FIXME:  which is probably true for Jar files, fwiw, but we don't
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   869
       !!! FIXME:  care about these values anyhow. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   870
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   871
    BAIL_IF_MACRO(!io->seek(io, entry->offset), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   872
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   873
    BAIL_IF_MACRO(ui32 != ZIP_LOCAL_FILE_SIG, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   874
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   875
    BAIL_IF_MACRO(ui16 != entry->version_needed, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   876
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);  /* general bits. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   877
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   878
    BAIL_IF_MACRO(ui16 != entry->compression_method, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   879
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);  /* date/time */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   880
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   881
    BAIL_IF_MACRO(ui32 && (ui32 != entry->crc), PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   882
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   883
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   884
    BAIL_IF_MACRO(ui32 && (ui32 != 0xFFFFFFFF) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   885
                  (ui32 != entry->compressed_size), PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   886
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   887
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   888
    BAIL_IF_MACRO(ui32 && (ui32 != 0xFFFFFFFF) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   889
                 (ui32 != entry->uncompressed_size), PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   890
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   891
    BAIL_IF_MACRO(!readui16(io, &fnamelen), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   892
    BAIL_IF_MACRO(!readui16(io, &extralen), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   893
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   894
    entry->offset += fnamelen + extralen + 30;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   895
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   896
} /* zip_parse_local */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   897
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   898
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   899
static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   900
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   901
    int retval = 1;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   902
    const ZipResolveType resolve_type = entry->resolved;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   903
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   904
    if (resolve_type == ZIP_DIRECTORY)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   905
        return 1;   /* we're good. */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   906
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   907
    /* Don't bother if we've failed to resolve this entry before. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   908
    BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_FILE, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   909
    BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_SYMLINK, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   910
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   911
    /* uhoh...infinite symlink loop! */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   912
    BAIL_IF_MACRO(resolve_type == ZIP_RESOLVING, PHYSFS_ERR_SYMLINK_LOOP, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   913
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   914
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   915
     * We fix up the offset to point to the actual data on the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   916
     *  first open, since we don't want to seek across the whole file on
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   917
     *  archive open (can be SLOW on large, CD-stored files), but we
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   918
     *  need to check the local file header...not just for corruption,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   919
     *  but since it stores offset info the central directory does not.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   920
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   921
    if (resolve_type != ZIP_RESOLVED)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   922
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   923
        entry->resolved = ZIP_RESOLVING;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   924
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   925
        retval = zip_parse_local(io, entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   926
        if (retval)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   927
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   928
            /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   929
             * If it's a symlink, find the original file. This will cause
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   930
             *  resolution of other entries (other symlinks and, eventually,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   931
             *  the real file) if all goes well.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   932
             */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   933
            if (resolve_type == ZIP_UNRESOLVED_SYMLINK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   934
                retval = zip_resolve_symlink(io, info, entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   935
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   936
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   937
        if (resolve_type == ZIP_UNRESOLVED_SYMLINK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   938
            entry->resolved = ((retval) ? ZIP_RESOLVED : ZIP_BROKEN_SYMLINK);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   939
        else if (resolve_type == ZIP_UNRESOLVED_FILE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   940
            entry->resolved = ((retval) ? ZIP_RESOLVED : ZIP_BROKEN_FILE);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   941
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   942
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   943
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   944
} /* zip_resolve */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   945
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   946
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   947
static int zip_hash_entry(ZIPinfo *info, ZIPentry *entry);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   948
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   949
/* Fill in missing parent directories. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   950
static ZIPentry *zip_hash_ancestors(ZIPinfo *info, char *name)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   951
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   952
    ZIPentry *retval = &info->root;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   953
    char *sep = strrchr(name, '/');
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   954
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   955
    if (sep)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   956
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   957
        const size_t namelen = (sep - name) + 1;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   958
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   959
        *sep = '\0';  /* chop off last piece. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   960
        retval = zip_find_entry(info, name);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   961
        *sep = '/';
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   962
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   963
        if (retval != NULL)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   964
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   965
            if (retval->resolved != ZIP_DIRECTORY)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   966
                BAIL_MACRO(PHYSFS_ERR_CORRUPT, NULL);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   967
            return retval;  /* already hashed. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   968
        } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   969
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   970
        /* okay, this is a new dir. Build and hash us. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   971
        retval = (ZIPentry *) allocator.Malloc(sizeof (ZIPentry) + namelen);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   972
        BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   973
        memset(retval, '\0', sizeof (*retval));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   974
        retval->name = ((char *) retval) + sizeof (ZIPentry);
12451
30da743f118b PHYSFS: fix off-by-one error
sheepluva
parents: 12213
diff changeset
   975
        memcpy(retval->name, name, namelen - 1);
30da743f118b PHYSFS: fix off-by-one error
sheepluva
parents: 12213
diff changeset
   976
        retval->name[namelen - 1] = '\0';
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   977
        retval->resolved = ZIP_DIRECTORY;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   978
        if (!zip_hash_entry(info, retval))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   979
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   980
            allocator.Free(retval);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   981
            return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   982
        } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   983
    } /* else */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   984
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   985
    return retval;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   986
} /* zip_hash_ancestors */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   987
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   988
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   989
static int zip_hash_entry(ZIPinfo *info, ZIPentry *entry)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   990
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   991
    PHYSFS_uint32 hashval;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   992
    ZIPentry *parent;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   993
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   994
    assert(!zip_find_entry(info, entry->name));  /* checked elsewhere */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   995
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   996
    parent = zip_hash_ancestors(info, entry->name);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   997
    if (!parent)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   998
        return 0;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
   999
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1000
    hashval = zip_hash_string(info, entry->name);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1001
    entry->hashnext = info->hash[hashval];
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1002
    info->hash[hashval] = entry;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1003
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1004
    entry->sibling = parent->children;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1005
    parent->children = entry;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1006
    return 1;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1007
} /* zip_hash_entry */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1008
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1009
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1010
static int zip_entry_is_symlink(const ZIPentry *entry)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1011
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1012
    return ((entry->resolved == ZIP_UNRESOLVED_SYMLINK) ||
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1013
            (entry->resolved == ZIP_BROKEN_SYMLINK) ||
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1014
            (entry->symlink));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1015
} /* zip_entry_is_symlink */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1016
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1017
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1018
static int zip_version_does_symlinks(PHYSFS_uint32 version)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1019
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1020
    int retval = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1021
    PHYSFS_uint8 hosttype = (PHYSFS_uint8) ((version >> 8) & 0xFF);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1022
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1023
    switch (hosttype)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1024
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1025
            /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1026
             * These are the platforms that can NOT build an archive with
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1027
             *  symlinks, according to the Info-ZIP project.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1028
             */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1029
        case 0:  /* FS_FAT_  */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1030
        case 1:  /* AMIGA_   */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1031
        case 2:  /* VMS_     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1032
        case 4:  /* VM_CSM_  */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1033
        case 6:  /* FS_HPFS_ */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1034
        case 11: /* FS_NTFS_ */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1035
        case 14: /* FS_VFAT_ */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1036
        case 13: /* ACORN_   */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1037
        case 15: /* MVS_     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1038
        case 18: /* THEOS_   */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1039
            break;  /* do nothing. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1040
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1041
        default:  /* assume the rest to be unix-like. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1042
            retval = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1043
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1044
    } /* switch */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1045
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1046
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1047
} /* zip_version_does_symlinks */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1048
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1049
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1050
static int zip_has_symlink_attr(ZIPentry *entry, PHYSFS_uint32 extern_attr)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1051
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1052
    PHYSFS_uint16 xattr = ((extern_attr >> 16) & 0xFFFF);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1053
    return ( (zip_version_does_symlinks(entry->version)) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1054
             (entry->uncompressed_size > 0) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1055
             ((xattr & UNIX_FILETYPE_MASK) == UNIX_FILETYPE_SYMLINK) );
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1056
} /* zip_has_symlink_attr */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1057
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1058
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1059
static PHYSFS_sint64 zip_dos_time_to_physfs_time(PHYSFS_uint32 dostime)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1060
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1061
    PHYSFS_uint32 dosdate;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1062
    struct tm unixtime;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1063
    memset(&unixtime, '\0', sizeof (unixtime));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1064
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1065
    dosdate = (PHYSFS_uint32) ((dostime >> 16) & 0xFFFF);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1066
    dostime &= 0xFFFF;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1067
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1068
    /* dissect date */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1069
    unixtime.tm_year = ((dosdate >> 9) & 0x7F) + 80;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1070
    unixtime.tm_mon  = ((dosdate >> 5) & 0x0F) - 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1071
    unixtime.tm_mday = ((dosdate     ) & 0x1F);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1072
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1073
    /* dissect time */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1074
    unixtime.tm_hour = ((dostime >> 11) & 0x1F);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1075
    unixtime.tm_min  = ((dostime >>  5) & 0x3F);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1076
    unixtime.tm_sec  = ((dostime <<  1) & 0x3E);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1077
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1078
    /* let mktime calculate daylight savings time. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1079
    unixtime.tm_isdst = -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1080
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1081
    return ((PHYSFS_sint64) mktime(&unixtime));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1082
} /* zip_dos_time_to_physfs_time */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1083
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1084
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1085
static ZIPentry *zip_load_entry(PHYSFS_Io *io, const int zip64,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1086
                                const PHYSFS_uint64 ofs_fixup)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1087
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1088
    ZIPentry entry;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1089
    ZIPentry *retval = NULL;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1090
    PHYSFS_uint16 fnamelen, extralen, commentlen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1091
    PHYSFS_uint32 external_attr;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1092
    PHYSFS_uint32 starting_disk;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1093
    PHYSFS_uint64 offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1094
    PHYSFS_uint16 ui16;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1095
    PHYSFS_uint32 ui32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1096
    PHYSFS_sint64 si64;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1097
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1098
    memset(&entry, '\0', sizeof (entry));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1099
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1100
    /* sanity check with central directory signature... */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1101
    if (!readui32(io, &ui32)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1102
    BAIL_IF_MACRO(ui32 != ZIP_CENTRAL_DIR_SIG, PHYSFS_ERR_CORRUPT, NULL);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1103
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1104
    /* Get the pertinent parts of the record... */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1105
    if (!readui16(io, &entry.version)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1106
    if (!readui16(io, &entry.version_needed)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1107
    if (!readui16(io, &entry.general_bits)) return NULL;  /* general bits */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1108
    if (!readui16(io, &entry.compression_method)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1109
    if (!readui32(io, &entry.dos_mod_time)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1110
    entry.last_mod_time = zip_dos_time_to_physfs_time(entry.dos_mod_time);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1111
    if (!readui32(io, &entry.crc)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1112
    if (!readui32(io, &ui32)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1113
    entry.compressed_size = (PHYSFS_uint64) ui32;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1114
    if (!readui32(io, &ui32)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1115
    entry.uncompressed_size = (PHYSFS_uint64) ui32;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1116
    if (!readui16(io, &fnamelen)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1117
    if (!readui16(io, &extralen)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1118
    if (!readui16(io, &commentlen)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1119
    if (!readui16(io, &ui16)) return NULL;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1120
    starting_disk = (PHYSFS_uint32) ui16;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1121
    if (!readui16(io, &ui16)) return NULL;  /* internal file attribs */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1122
    if (!readui32(io, &external_attr)) return NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1123
    if (!readui32(io, &ui32)) return NULL;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1124
    offset = (PHYSFS_uint64) ui32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1125
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1126
    retval = (ZIPentry *) allocator.Malloc(sizeof (ZIPentry) + fnamelen + 1);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1127
    BAIL_IF_MACRO(retval == NULL, PHYSFS_ERR_OUT_OF_MEMORY, 0);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1128
    memcpy(retval, &entry, sizeof (*retval));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1129
    retval->name = ((char *) retval) + sizeof (ZIPentry);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1130
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1131
    if (!__PHYSFS_readAll(io, retval->name, fnamelen))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1132
        goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1133
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1134
    retval->name[fnamelen] = '\0';  /* null-terminate the filename. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1135
    zip_convert_dos_path(retval, retval->name);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1136
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1137
    retval->symlink = NULL;  /* will be resolved later, if necessary. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1138
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1139
    if (retval->name[fnamelen - 1] == '/')
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1140
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1141
        retval->name[fnamelen - 1] = '\0';
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1142
        retval->resolved = ZIP_DIRECTORY;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1143
    } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1144
    else
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1145
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1146
        retval->resolved = (zip_has_symlink_attr(&entry, external_attr)) ?
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1147
                                ZIP_UNRESOLVED_SYMLINK : ZIP_UNRESOLVED_FILE;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1148
    } /* else */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1149
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1150
    si64 = io->tell(io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1151
    if (si64 == -1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1152
        goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1153
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1154
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1155
     * The actual sizes didn't fit in 32-bits; look for the Zip64
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1156
     *  extended information extra field...
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1157
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1158
    if ( (zip64) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1159
         ((offset == 0xFFFFFFFF) ||
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1160
          (starting_disk == 0xFFFFFFFF) ||
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1161
          (retval->compressed_size == 0xFFFFFFFF) ||
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1162
          (retval->uncompressed_size == 0xFFFFFFFF)) )
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1163
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1164
        int found = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1165
        PHYSFS_uint16 sig, len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1166
        while (extralen > 4)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1167
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1168
            if (!readui16(io, &sig))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1169
                goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1170
            else if (!readui16(io, &len))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1171
                goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1172
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1173
            si64 += 4 + len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1174
            extralen -= 4 + len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1175
            if (sig != ZIP64_EXTENDED_INFO_EXTRA_FIELD_SIG)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1176
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1177
                if (!io->seek(io, si64))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1178
                    goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1179
                continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1180
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1181
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1182
            found = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1183
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1184
        } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1185
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1186
        GOTO_IF_MACRO(!found, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1187
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1188
        if (retval->uncompressed_size == 0xFFFFFFFF)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1189
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1190
            GOTO_IF_MACRO(len < 8, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1191
            if (!readui64(io, &retval->uncompressed_size))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1192
                goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1193
            len -= 8;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1194
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1195
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1196
        if (retval->compressed_size == 0xFFFFFFFF)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1197
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1198
            GOTO_IF_MACRO(len < 8, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1199
            if (!readui64(io, &retval->compressed_size))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1200
                goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1201
            len -= 8;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1202
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1203
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1204
        if (offset == 0xFFFFFFFF)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1205
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1206
            GOTO_IF_MACRO(len < 8, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1207
            if (!readui64(io, &offset))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1208
                goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1209
            len -= 8;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1210
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1211
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1212
        if (starting_disk == 0xFFFFFFFF)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1213
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1214
            GOTO_IF_MACRO(len < 8, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1215
            if (!readui32(io, &starting_disk))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1216
                goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1217
            len -= 4;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1218
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1219
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1220
        GOTO_IF_MACRO(len != 0, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1221
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1222
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1223
    GOTO_IF_MACRO(starting_disk != 0, PHYSFS_ERR_CORRUPT, zip_load_entry_puked);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1224
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1225
    retval->offset = offset + ofs_fixup;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1226
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1227
    /* seek to the start of the next entry in the central directory... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1228
    if (!io->seek(io, si64 + extralen + commentlen))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1229
        goto zip_load_entry_puked;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1230
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1231
    return retval;  /* success. */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1232
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1233
zip_load_entry_puked:
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1234
    allocator.Free(retval);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1235
    return NULL;  /* failure. */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1236
} /* zip_load_entry */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1237
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1238
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1239
/* This leaves things allocated on error; the caller will clean up the mess. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1240
static int zip_load_entries(ZIPinfo *info,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1241
                            const PHYSFS_uint64 data_ofs,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1242
                            const PHYSFS_uint64 central_ofs,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1243
                            const PHYSFS_uint64 entry_count)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1244
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1245
    PHYSFS_Io *io = info->io;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1246
    const int zip64 = info->zip64;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1247
    PHYSFS_uint64 i;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1248
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1249
    if (!io->seek(io, central_ofs))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1250
        return 0;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1251
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1252
    for (i = 0; i < entry_count; i++)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1253
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1254
        ZIPentry *entry = zip_load_entry(io, zip64, data_ofs);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1255
        ZIPentry *find;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1256
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1257
        if (!entry)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1258
            return 0;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1259
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1260
        find = zip_find_entry(info, entry->name);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1261
        if (find != NULL)  /* duplicate? */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1262
        {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1263
            if (find->last_mod_time != 0)  /* duplicate? */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1264
            {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1265
                allocator.Free(entry);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1266
                BAIL_MACRO(PHYSFS_ERR_CORRUPT, 0);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1267
            } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1268
            else  /* we filled this in as a placeholder. Update it. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1269
            {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1270
                find->offset = entry->offset;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1271
                find->version = entry->version;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1272
                find->version_needed = entry->version_needed;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1273
                find->compression_method = entry->compression_method;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1274
                find->crc = entry->crc;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1275
                find->compressed_size = entry->compressed_size;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1276
                find->uncompressed_size = entry->uncompressed_size;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1277
                find->last_mod_time = entry->last_mod_time;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1278
                allocator.Free(entry);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1279
                continue;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1280
            } /* else */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1281
        } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1282
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1283
        if (!zip_hash_entry(info, entry))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1284
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1285
            allocator.Free(entry);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1286
            return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1287
        } /* if */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1288
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1289
        if (zip_entry_is_tradional_crypto(entry))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1290
            info->has_crypto = 1;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1291
    } /* for */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1292
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1293
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1294
} /* zip_load_entries */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1295
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1296
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1297
static PHYSFS_sint64 zip64_find_end_of_central_dir(PHYSFS_Io *io,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1298
                                                   PHYSFS_sint64 _pos,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1299
                                                   PHYSFS_uint64 offset)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1300
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1301
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1302
     * Naturally, the offset is useless to us; it is the offset from the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1303
     *  start of file, which is meaningless if we've appended this .zip to
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1304
     *  a self-extracting .exe. We need to find this on our own. It should
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1305
     *  be directly before the locator record, but the record in question,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1306
     *  like the original end-of-central-directory record, ends with a
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1307
     *  variable-length field. Unlike the original, which has to store the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1308
     *  size of that variable-length field in a 16-bit int and thus has to be
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1309
     *  within 64k, the new one gets 64-bits.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1310
     *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1311
     * Fortunately, the only currently-specified record for that variable
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1312
     *  length block is some weird proprietary thing that deals with EBCDIC
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1313
     *  and tape backups or something. So we don't seek far.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1314
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1315
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1316
    PHYSFS_uint32 ui32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1317
    const PHYSFS_uint64 pos = (PHYSFS_uint64) _pos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1318
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1319
    assert(_pos > 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1320
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1321
    /* Try offset specified in the Zip64 end of central directory locator. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1322
    /* This works if the entire PHYSFS_Io is the zip file. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1323
    BAIL_IF_MACRO(!io->seek(io, offset), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1324
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1325
    if (ui32 == ZIP64_END_OF_CENTRAL_DIR_SIG)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1326
        return offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1327
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1328
    /* Try 56 bytes before the Zip64 end of central directory locator. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1329
    /* This works if the record isn't variable length and is version 1. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1330
    if (pos > 56)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1331
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1332
        BAIL_IF_MACRO(!io->seek(io, pos-56), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1333
        BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1334
        if (ui32 == ZIP64_END_OF_CENTRAL_DIR_SIG)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1335
            return pos-56;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1336
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1337
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1338
    /* Try 84 bytes before the Zip64 end of central directory locator. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1339
    /* This works if the record isn't variable length and is version 2. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1340
    if (pos > 84)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1341
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1342
        BAIL_IF_MACRO(!io->seek(io, pos-84), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1343
        BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1344
        if (ui32 == ZIP64_END_OF_CENTRAL_DIR_SIG)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1345
            return pos-84;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1346
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1347
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1348
    /* Ok, brute force: we know it's between (offset) and (pos) somewhere. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1349
    /*  Just try moving back at most 256k. Oh well. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1350
    if ((offset < pos) && (pos > 4))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1351
    {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1352
        const PHYSFS_uint64 maxbuflen = 256 * 1024;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1353
        PHYSFS_uint64 len = pos - offset;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1354
        PHYSFS_uint8 *buf = NULL;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1355
        PHYSFS_sint32 i;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1356
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1357
        if (len > maxbuflen)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1358
            len = maxbuflen;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1359
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1360
        buf = (PHYSFS_uint8 *) __PHYSFS_smallAlloc(len);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1361
        BAIL_IF_MACRO(!buf, PHYSFS_ERR_OUT_OF_MEMORY, -1);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1362
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1363
        if (!io->seek(io, pos - len) || !__PHYSFS_readAll(io, buf, len))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1364
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1365
            __PHYSFS_smallFree(buf);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1366
            return -1;  /* error was set elsewhere. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1367
        } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1368
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1369
        for (i = (PHYSFS_sint32) (len - 4); i >= 0; i--)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1370
        {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1371
            if ( (buf[i] == 0x50) && (buf[i+1] == 0x4b) &&
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1372
                 (buf[i+2] == 0x06) && (buf[i+3] == 0x06) )
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1373
            {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1374
                __PHYSFS_smallFree(buf);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1375
                return pos - (len - i);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1376
            } /* if */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1377
        } /* for */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1378
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1379
        __PHYSFS_smallFree(buf);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1380
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1381
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1382
    BAIL_MACRO(PHYSFS_ERR_CORRUPT, -1);  /* didn't find it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1383
} /* zip64_find_end_of_central_dir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1384
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1385
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1386
static int zip64_parse_end_of_central_dir(ZIPinfo *info,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1387
                                          PHYSFS_uint64 *data_start,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1388
                                          PHYSFS_uint64 *dir_ofs,
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1389
                                          PHYSFS_uint64 *entry_count,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1390
                                          PHYSFS_sint64 pos)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1391
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1392
    PHYSFS_Io *io = info->io;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1393
    PHYSFS_uint64 ui64;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1394
    PHYSFS_uint32 ui32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1395
    PHYSFS_uint16 ui16;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1396
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1397
    /* We should be positioned right past the locator signature. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1398
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1399
    if ((pos < 0) || (!io->seek(io, pos)))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1400
        return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1401
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1402
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1403
    if (ui32 != ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIG)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1404
        return -1;  /* it's not a Zip64 archive. Not an error, though! */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1405
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1406
    info->zip64 = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1407
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1408
    /* number of the disk with the start of the central directory. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1409
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1410
    BAIL_IF_MACRO(ui32 != 0, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1411
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1412
    /* offset of Zip64 end of central directory record. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1413
    BAIL_IF_MACRO(!readui64(io, &ui64), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1414
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1415
    /* total number of disks */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1416
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1417
    BAIL_IF_MACRO(ui32 != 1, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1418
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1419
    pos = zip64_find_end_of_central_dir(io, pos, ui64);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1420
    if (pos < 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1421
        return 0;  /* oh well. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1422
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1423
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1424
     * For self-extracting archives, etc, there's crapola in the file
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1425
     *  before the zipfile records; we calculate how much data there is
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1426
     *  prepended by determining how far the zip64-end-of-central-directory
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1427
     *  offset is from where it is supposed to be...the difference in bytes
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1428
     *  is how much arbitrary data is at the start of the physical file.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1429
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1430
    assert(((PHYSFS_uint64) pos) >= ui64);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1431
    *data_start = ((PHYSFS_uint64) pos) - ui64;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1432
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1433
    BAIL_IF_MACRO(!io->seek(io, pos), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1434
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1435
    /* check signature again, just in case. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1436
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1437
    BAIL_IF_MACRO(ui32 != ZIP64_END_OF_CENTRAL_DIR_SIG, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1438
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1439
    /* size of Zip64 end of central directory record. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1440
    BAIL_IF_MACRO(!readui64(io, &ui64), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1441
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1442
    /* version made by. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1443
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1444
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1445
    /* version needed to extract. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1446
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1447
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1448
    /* number of this disk. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1449
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1450
    BAIL_IF_MACRO(ui32 != 0, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1451
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1452
    /* number of disk with start of central directory record. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1453
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1454
    BAIL_IF_MACRO(ui32 != 0, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1455
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1456
    /* total number of entries in the central dir on this disk */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1457
    BAIL_IF_MACRO(!readui64(io, &ui64), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1458
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1459
    /* total number of entries in the central dir */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1460
    BAIL_IF_MACRO(!readui64(io, entry_count), ERRPASS, 0);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1461
    BAIL_IF_MACRO(ui64 != *entry_count, PHYSFS_ERR_CORRUPT, 0);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1462
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1463
    /* size of the central directory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1464
    BAIL_IF_MACRO(!readui64(io, &ui64), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1465
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1466
    /* offset of central directory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1467
    BAIL_IF_MACRO(!readui64(io, dir_ofs), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1468
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1469
    /* Since we know the difference, fix up the central dir offset... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1470
    *dir_ofs += *data_start;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1471
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1472
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1473
     * There are more fields here, for encryption and feature-specific things,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1474
     *  but we don't care about any of them at the moment.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1475
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1476
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1477
    return 1;  /* made it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1478
} /* zip64_parse_end_of_central_dir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1479
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1480
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1481
static int zip_parse_end_of_central_dir(ZIPinfo *info,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1482
                                        PHYSFS_uint64 *data_start,
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1483
                                        PHYSFS_uint64 *dir_ofs,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1484
                                        PHYSFS_uint64 *entry_count)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1485
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1486
    PHYSFS_Io *io = info->io;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1487
    PHYSFS_uint16 entryCount16;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1488
    PHYSFS_uint32 offset32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1489
    PHYSFS_uint32 ui32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1490
    PHYSFS_uint16 ui16;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1491
    PHYSFS_sint64 len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1492
    PHYSFS_sint64 pos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1493
    int rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1494
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1495
    /* find the end-of-central-dir record, and seek to it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1496
    pos = zip_find_end_of_central_dir(io, &len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1497
    BAIL_IF_MACRO(pos == -1, ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1498
    BAIL_IF_MACRO(!io->seek(io, pos), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1499
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1500
    /* check signature again, just in case. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1501
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1502
    BAIL_IF_MACRO(ui32 != ZIP_END_OF_CENTRAL_DIR_SIG, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1503
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1504
    /* Seek back to see if "Zip64 end of central directory locator" exists. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1505
    /* this record is 20 bytes before end-of-central-dir */
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1506
    rc = zip64_parse_end_of_central_dir(info, data_start, dir_ofs,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1507
                                        entry_count, pos - 20);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1508
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1509
    /* Error or success? Bounce out of here. Keep going if not zip64. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1510
    if ((rc == 0) || (rc == 1))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1511
        return rc;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1512
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1513
    assert(rc == -1);  /* no error, just not a Zip64 archive. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1514
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1515
    /* Not Zip64? Seek back to where we were and keep processing. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1516
    BAIL_IF_MACRO(!io->seek(io, pos + 4), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1517
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1518
    /* number of this disk */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1519
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1520
    BAIL_IF_MACRO(ui16 != 0, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1521
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1522
    /* number of the disk with the start of the central directory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1523
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1524
    BAIL_IF_MACRO(ui16 != 0, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1525
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1526
    /* total number of entries in the central dir on this disk */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1527
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1528
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1529
    /* total number of entries in the central dir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1530
    BAIL_IF_MACRO(!readui16(io, &entryCount16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1531
    BAIL_IF_MACRO(ui16 != entryCount16, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1532
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1533
    *entry_count = entryCount16;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1534
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1535
    /* size of the central directory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1536
    BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1537
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1538
    /* offset of central directory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1539
    BAIL_IF_MACRO(!readui32(io, &offset32), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1540
    *dir_ofs = (PHYSFS_uint64) offset32;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1541
    BAIL_IF_MACRO(pos < (*dir_ofs + ui32), PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1542
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1543
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1544
     * For self-extracting archives, etc, there's crapola in the file
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1545
     *  before the zipfile records; we calculate how much data there is
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1546
     *  prepended by determining how far the central directory offset is
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1547
     *  from where it is supposed to be (start of end-of-central-dir minus
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1548
     *  sizeof central dir)...the difference in bytes is how much arbitrary
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1549
     *  data is at the start of the physical file.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1550
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1551
    *data_start = (PHYSFS_uint64) (pos - (*dir_ofs + ui32));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1552
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1553
    /* Now that we know the difference, fix up the central dir offset... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1554
    *dir_ofs += *data_start;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1555
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1556
    /* zipfile comment length */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1557
    BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1558
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1559
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1560
     * Make sure that the comment length matches to the end of file...
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1561
     *  If it doesn't, we're either in the wrong part of the file, or the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1562
     *  file is corrupted, but we give up either way.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1563
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1564
    BAIL_IF_MACRO((pos + 22 + ui16) != len, PHYSFS_ERR_CORRUPT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1565
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1566
    return 1;  /* made it. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1567
} /* zip_parse_end_of_central_dir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1568
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1569
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1570
static int zip_alloc_hashtable(ZIPinfo *info, const PHYSFS_uint64 entry_count)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1571
{
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1572
    size_t alloclen;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1573
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1574
    info->hashBuckets = (size_t) (entry_count / 5);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1575
    if (!info->hashBuckets)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1576
        info->hashBuckets = 1;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1577
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1578
    alloclen = info->hashBuckets * sizeof (ZIPentry *);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1579
    info->hash = (ZIPentry **) allocator.Malloc(alloclen);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1580
    BAIL_IF_MACRO(!info->hash, PHYSFS_ERR_OUT_OF_MEMORY, 0);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1581
    memset(info->hash, '\0', alloclen);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1582
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1583
    return 1;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1584
} /* zip_alloc_hashtable */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1585
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1586
static void ZIP_closeArchive(void *opaque);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1587
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1588
static void *ZIP_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1589
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1590
    ZIPinfo *info = NULL;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1591
    PHYSFS_uint64 dstart;  /* data start */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1592
    PHYSFS_uint64 cdir_ofs;  /* central dir offset */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1593
    PHYSFS_uint64 entry_count;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1594
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1595
    assert(io != NULL);  /* shouldn't ever happen. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1596
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1597
    BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1598
    BAIL_IF_MACRO(!isZip(io), ERRPASS, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1599
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1600
    info = (ZIPinfo *) allocator.Malloc(sizeof (ZIPinfo));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1601
    BAIL_IF_MACRO(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1602
    memset(info, '\0', sizeof (ZIPinfo));
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1603
    info->root.resolved = ZIP_DIRECTORY;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1604
    info->io = io;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1605
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1606
    if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &entry_count))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1607
        goto ZIP_openarchive_failed;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1608
    else if (!zip_alloc_hashtable(info, entry_count))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1609
        goto ZIP_openarchive_failed;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1610
    else if (!zip_load_entries(info, dstart, cdir_ofs, entry_count))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1611
        goto ZIP_openarchive_failed;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1612
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1613
    assert(info->root.sibling == NULL);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1614
    return info;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1615
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1616
ZIP_openarchive_failed:
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1617
    info->io = NULL;  /* don't let ZIP_closeArchive destroy (io). */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1618
    ZIP_closeArchive(info);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1619
    return NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1620
} /* ZIP_openArchive */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1621
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1622
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1623
static void ZIP_enumerateFiles(void *opaque, const char *dname,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1624
                               PHYSFS_EnumFilesCallback cb,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1625
                               const char *origdir, void *callbackdata)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1626
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1627
    ZIPinfo *info = ((ZIPinfo *) opaque);
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1628
    const ZIPentry *entry = zip_find_entry(info, dname);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1629
    if (entry && (entry->resolved == ZIP_DIRECTORY))
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1630
    {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1631
        for (entry = entry->children; entry; entry = entry->sibling)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1632
        {
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1633
            const char *ptr = strrchr(entry->name, '/');
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1634
            cb(callbackdata, origdir, ptr ? ptr + 1 : entry->name);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1635
        } /* for */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1636
    } /* if */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1637
} /* ZIP_enumerateFiles */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1638
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1639
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1640
static PHYSFS_Io *zip_get_io(PHYSFS_Io *io, ZIPinfo *inf, ZIPentry *entry)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1641
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1642
    int success;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1643
    PHYSFS_Io *retval = io->duplicate(io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1644
    BAIL_IF_MACRO(!retval, ERRPASS, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1645
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1646
    /* !!! FIXME: if you open a dir here, it should bail ERR_NOT_A_FILE */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1647
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1648
    /* (inf) can be NULL if we already resolved. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1649
    success = (inf == NULL) || zip_resolve(retval, inf, entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1650
    if (success)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1651
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1652
        PHYSFS_sint64 offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1653
        offset = ((entry->symlink) ? entry->symlink->offset : entry->offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1654
        success = retval->seek(retval, offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1655
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1656
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1657
    if (!success)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1658
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1659
        retval->destroy(retval);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1660
        retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1661
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1662
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1663
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1664
} /* zip_get_io */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1665
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1666
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1667
static PHYSFS_Io *ZIP_openRead(void *opaque, const char *filename)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1668
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1669
    PHYSFS_Io *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1670
    ZIPinfo *info = (ZIPinfo *) opaque;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1671
    ZIPentry *entry = zip_find_entry(info, filename);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1672
    ZIPfileinfo *finfo = NULL;
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1673
    PHYSFS_Io *io = NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1674
    PHYSFS_uint8 *password = NULL;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1675
    int i;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1676
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1677
    /* if not found, see if maybe "$PASSWORD" is appended. */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1678
    if ((!entry) && (info->has_crypto))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1679
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1680
        const char *ptr = strrchr(filename, '$');
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1681
        if (ptr != NULL)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1682
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1683
            const PHYSFS_uint64 len = (PHYSFS_uint64) (ptr - filename);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1684
            char *str = (char *) __PHYSFS_smallAlloc(len + 1);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1685
            BAIL_IF_MACRO(!str, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1686
            memcpy(str, filename, len);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1687
            str[len] = '\0';
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1688
            entry = zip_find_entry(info, str);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1689
            __PHYSFS_smallFree(str);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1690
            password = (PHYSFS_uint8 *) (ptr + 1);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1691
        } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1692
    } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1693
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1694
    BAIL_IF_MACRO(!entry, ERRPASS, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1695
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1696
    retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1697
    GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_openRead_failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1698
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1699
    finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1700
    GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_openRead_failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1701
    memset(finfo, '\0', sizeof (ZIPfileinfo));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1702
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1703
    io = zip_get_io(info->io, info, entry);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1704
    GOTO_IF_MACRO(!io, ERRPASS, ZIP_openRead_failed);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1705
    finfo->io = io;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1706
    finfo->entry = ((entry->symlink != NULL) ? entry->symlink : entry);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1707
    initializeZStream(&finfo->stream);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1708
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1709
    if (finfo->entry->compression_method != COMPMETH_NONE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1710
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1711
        finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1712
        if (!finfo->buffer)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1713
            GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, ZIP_openRead_failed);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1714
        else if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1715
            goto ZIP_openRead_failed;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1716
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1717
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1718
    if (!zip_entry_is_tradional_crypto(entry))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1719
        GOTO_IF_MACRO(password != NULL, PHYSFS_ERR_BAD_PASSWORD, ZIP_openRead_failed);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1720
    else
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1721
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1722
        PHYSFS_uint8 crypto_header[12];
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1723
        GOTO_IF_MACRO(password == NULL, PHYSFS_ERR_BAD_PASSWORD, ZIP_openRead_failed);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1724
        if (io->read(io, crypto_header, 12) != 12)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1725
            goto ZIP_openRead_failed;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1726
        else if (!zip_prep_crypto_keys(finfo, crypto_header, password))
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1727
            goto ZIP_openRead_failed;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1728
    } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1729
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1730
    memcpy(retval, &ZIP_Io, sizeof (PHYSFS_Io));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1731
    retval->opaque = finfo;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1732
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1733
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1734
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1735
ZIP_openRead_failed:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1736
    if (finfo != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1737
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1738
        if (finfo->io != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1739
            finfo->io->destroy(finfo->io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1740
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1741
        if (finfo->buffer != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1742
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1743
            allocator.Free(finfo->buffer);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1744
            inflateEnd(&finfo->stream);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1745
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1746
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1747
        allocator.Free(finfo);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1748
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1749
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1750
    if (retval != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1751
        allocator.Free(retval);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1752
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1753
    return NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1754
} /* ZIP_openRead */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1755
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1756
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1757
static PHYSFS_Io *ZIP_openWrite(void *opaque, const char *filename)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1758
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1759
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1760
} /* ZIP_openWrite */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1761
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1762
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1763
static PHYSFS_Io *ZIP_openAppend(void *opaque, const char *filename)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1764
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1765
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1766
} /* ZIP_openAppend */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1767
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1768
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1769
static void ZIP_closeArchive(void *opaque)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1770
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1771
    ZIPinfo *info = (ZIPinfo *) (opaque);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1772
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1773
    if (!info)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1774
        return;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1775
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1776
    if (info->io)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1777
        info->io->destroy(info->io);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1778
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1779
    assert(info->root.sibling == NULL);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1780
    assert(info->hash || (info->root.children == NULL));
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1781
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1782
    if (info->hash)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1783
    {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1784
        size_t i;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1785
        for (i = 0; i < info->hashBuckets; i++)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1786
        {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1787
            ZIPentry *entry;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1788
            ZIPentry *next;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1789
            for (entry = info->hash[i]; entry; entry = next)
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1790
            {
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1791
                next = entry->hashnext;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1792
                allocator.Free(entry);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1793
            } /* for */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1794
        } /* for */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1795
        allocator.Free(info->hash);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1796
    } /* if */
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1797
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1798
    allocator.Free(info);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1799
} /* ZIP_closeArchive */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1800
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1801
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1802
static int ZIP_remove(void *opaque, const char *name)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1803
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1804
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1805
} /* ZIP_remove */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1806
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1807
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1808
static int ZIP_mkdir(void *opaque, const char *name)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1809
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1810
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1811
} /* ZIP_mkdir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1812
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1813
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1814
static int ZIP_stat(void *opaque, const char *filename, PHYSFS_Stat *stat)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1815
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1816
    ZIPinfo *info = (ZIPinfo *) opaque;
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1817
    const ZIPentry *entry = zip_find_entry(info, filename);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1818
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1819
    /* !!! FIXME: does this need to resolve entries here? */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1820
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1821
    if (entry == NULL)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1822
        return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1823
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1824
    else if (entry->resolved == ZIP_DIRECTORY)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1825
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1826
        stat->filesize = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1827
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1828
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1829
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1830
    else if (zip_entry_is_symlink(entry))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1831
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1832
        stat->filesize = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1833
        stat->filetype = PHYSFS_FILETYPE_SYMLINK;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1834
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1835
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1836
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1837
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1838
        stat->filesize = (PHYSFS_sint64) entry->uncompressed_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1839
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1840
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1841
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1842
    stat->modtime = ((entry) ? entry->last_mod_time : 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1843
    stat->createtime = stat->modtime;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1844
    stat->accesstime = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1845
    stat->readonly = 1; /* .zip files are always read only */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1846
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1847
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1848
} /* ZIP_stat */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1849
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1850
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1851
const PHYSFS_Archiver __PHYSFS_Archiver_ZIP =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1852
{
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1853
    CURRENT_PHYSFS_ARCHIVER_API_VERSION,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1854
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1855
        "ZIP",
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1856
        "PkZip/WinZip/Info-Zip compatible",
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1857
        "Ryan C. Gordon <icculus@icculus.org>",
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1858
        "https://icculus.org/physfs/",
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1859
        1,  /* supportsSymlinks */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1860
    },
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1861
    ZIP_openArchive,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1862
    ZIP_enumerateFiles,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1863
    ZIP_openRead,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1864
    ZIP_openWrite,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1865
    ZIP_openAppend,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1866
    ZIP_remove,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1867
    ZIP_mkdir,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1868
    ZIP_stat,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1869
    ZIP_closeArchive
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1870
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1871
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1872
#endif  /* defined PHYSFS_SUPPORTS_ZIP */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1873
12213
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 12212
diff changeset
  1874
/* end of archiver_zip.c ... */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
  1875