zziplib update

git-svn: trunk@16
remotes/push_mirror/metadata
Tomasz Kojm 22 years ago
parent d4d142187b
commit 9750dd752c
  1. 4
      clamav-devel/ChangeLog
  2. 4
      clamav-devel/acinclude.m4
  3. 4
      clamav-devel/aclocal.m4
  4. 2
      clamav-devel/docs/FreeBSD-HowTo/qmail-scanner-how-to.html
  5. 43
      clamav-devel/libclamav/zziplib/zzip-conf.h
  6. 3
      clamav-devel/libclamav/zziplib/zzip-dir.c
  7. 58
      clamav-devel/libclamav/zziplib/zzip-file.c
  8. 8
      clamav-devel/libclamav/zziplib/zzip-file.h
  9. 1
      clamav-devel/libclamav/zziplib/zzip-io.c
  10. 212
      clamav-devel/libclamav/zziplib/zzip-zip.c
  11. 3
      clamav-devel/libclamav/zziplib/zzip.h
  12. 23
      clamav-devel/libclamav/zziplib/zziplib.h
  13. 2
      clamav-devel/mkinstalldirs

@ -1,3 +1,7 @@
Sun Aug 3 03:35:49 CEST 2003
-----------------------------
* libclamav: zziplib updated to 0.10.83-pre1
Sat Jul 26 17:11:46 CEST 2003
-----------------------------
* libclamav: updated mbox code (Nigel)

@ -68,7 +68,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for
dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created
dnl (the prefix is a bit different, since we add an extra -target- and -host-)
dnl
dnl @version: $Id: acinclude.m4,v 1.2 2003/08/02 22:37:52 kojm Exp $
dnl @version: $Id: acinclude.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $
dnl @author Guido Draheim <guidod@gmx.de> STATUS: used often
AC_DEFUN([AC_CREATE_TARGET_H],
@ -4110,7 +4110,7 @@ dnl AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
dnl AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
dnl
dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
dnl @version $Id: acinclude.m4,v 1.2 2003/08/02 22:37:52 kojm Exp $
dnl @version $Id: acinclude.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $
dnl
AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
[changequote(<<, >>)dnl

@ -81,7 +81,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for
dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created
dnl (the prefix is a bit different, since we add an extra -target- and -host-)
dnl
dnl @version: $Id: aclocal.m4,v 1.2 2003/08/02 22:37:52 kojm Exp $
dnl @version: $Id: aclocal.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $
dnl @author Guido Draheim <guidod@gmx.de> STATUS: used often
AC_DEFUN([AC_CREATE_TARGET_H],
@ -4041,7 +4041,7 @@ dnl AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
dnl AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
dnl
dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
dnl @version $Id: aclocal.m4,v 1.2 2003/08/02 22:37:52 kojm Exp $
dnl @version $Id: aclocal.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $
dnl
AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
[changequote(<<, >>)dnl

@ -31,7 +31,7 @@
<p class="COPYRIGHT">Copyright &copy; 2002 by Paul Hoadley and
Eric Parsonage</p>
<p class="PUBDATE">$Date: 2003/08/02 22:37:52 $<br>
<p class="PUBDATE">$Date: 2003/08/03 22:25:30 $<br>
</p>
<div>

@ -2,7 +2,7 @@
* Author:
* Guido Draheim <guidod@gmx.de>
*
* Copyright (c) 2001 Guido Draheim
* Copyright (c) 2001,2002,2003 Guido Draheim
* All rights reserved,
* use under the restrictions of the
* Lesser GNU General Public License
@ -53,15 +53,34 @@
#define _zzip_inline inline
#endif
#endif
#ifndef _zzip_size_t
#ifdef ZZIP_size_t
#define _zzip_size_t ZZIP_size_t
#else
#define _zzip_size_t size_t
#endif
#endif
#ifndef _zzip_ssize_t
#ifdef ZZIP_ssize_t
#define _zzip_ssize_t ZZIP_ssize_t
#else
#define _zzip_ssize_t ssize_t
#endif
#endif
/* whether this library shall use a 64bit off_t largefile variant in 64on32: */
/* (some exported names must be renamed to avoid bad calls after linking) */
#if defined ZZIP_LARGEFILE_SENSITIVE && _FILE_OFFSET_BITS+0 == 64
#define ZZIP_LARGEFILE_RENAME
#elif defined _LARGE_FILES /* on AIX */
#define ZZIP_LARGEFILE_RENAME
#if defined ZZIP_LARGEFILE_SENSITIVE
# if _FILE_OFFSET_BITS+0 == 64
# define ZZIP_LARGEFILE_RENAME
# elif defined _LARGE_FILES /* used on older AIX to get at 64bit off_t */
# define ZZIP_LARGEFILE_RENAME
# elif defined _ZZIP_LARGEFILE /* or simply use this one for zzip64 runs */
# define ZZIP_LARGEFILE_RENAME
# endif
#endif
/* if some were forgotten but required to have 64bit off_t largefile.. */
/* if the environment did not setup these for 64bit off_t largefile... */
#ifdef ZZIP_LARGEFILE_RENAME
# ifndef _FILE_OFFSET_BITS
# ifdef ZZIP__FILE_OFFSET_BITS /* == 64 */
@ -70,7 +89,12 @@
# endif
# ifndef _LARGE_FILES
# ifdef ZZIP__LARGE_FILES /* == 1 */
# define _LARGE_FILES 1
# define _LARGE_FILES ZZIP__LARGE_FILES
# endif
# endif
# ifndef _LARGEFILE_SOURCE
# ifdef ZZIP__LARGEFILE_SOURCE /* == 1 */
# define _LARGEFILE_SOURCE ZZIP__LARGEFILE_SOURCE
# endif
# endif
#endif
@ -141,6 +165,11 @@
#define __attribute__(X)
#endif
#if defined ZZIP_EXPORTS || defined ZZIPLIB_EXPORTS
# undef ZZIP_DLL
#define ZZIP_DLL 1
#endif
/* based on zconf.h : */
/* compile with -DZZIP_DLL for Windows DLL support */
#if defined ZZIP_DLL

@ -1,4 +1,3 @@
#define USE_DIRENT 0
/*
* Author:
* Guido Draheim <guidod@gmx.de>
@ -39,6 +38,8 @@
# endif
#endif
#define USE_DIRENT 0
/**
* This function is the equivalent of a => rewinddir(2) for a realdir or
* the zipfile in place of a directory. The ZZIP_DIR handle returned from

@ -88,17 +88,14 @@ zzip_file_saveoffset(ZZIP_FILE * fp)
return 0;
}
# ifndef ZZIP_CHECK_BACKSLASH_DIRSEPARATOR
# define ZZIP_CHECK_BACKSLASH_DIRSEPARATOR 0
# ifndef ZZIP_CHECK_BACKSLASH_DIRSEPARATOR /* NOTE: also default */
# define ZZIP_CHECK_BACKSLASH_DIRSEPARATOR 0 /* to "NO" on win32 ! */
# endif
# if !defined strcasecmp && !defined ZZIP_HAVE_STRCASECMP
# define ZZIP_CHECK_BACKSLASH_DIRSEPARATOR 1
# endif
#if ! ZZIP_CHECK_BACKSLASH_DIRSEPARATOR+0
#define dirsep_strrchr(N,C) strrchr(N,C)
#define dirsep_casecmp strcasecmp
@ -222,11 +219,11 @@ zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int o_mode)
{ /* skip local header - should test tons of other info,
* but trust that those are correct */
int dataoff;
zzip_ssize_t dataoff;
struct zzip_file_header * p = (void*) fp->buf32k;
dataoff = dir->io->read(dir->fd, (void*)p, sizeof(*p));
if (dataoff < (int) sizeof(*p))
if (dataoff < (zzip_ssize_t)sizeof(*p))
{ err = ZZIP_DIR_READ; goto error; }
if (! ZZIP_FILE_HEADER_CHECKMAGIC(p)) /* PK\3\4 */
{ err = ZZIP_CORRUPTED; goto error; }
@ -323,12 +320,12 @@ zzip_close(ZZIP_FILE* fp)
* required just that but the latest zlib would work just fine with
* a smaller buffer.
*/
int
zzip_file_read(ZZIP_FILE * fp, char * buf, int len)
zzip_ssize_t
zzip_file_read(ZZIP_FILE * fp, char * buf, zzip_size_t len)
{
ZZIP_DIR * dir;
int l;
int rv;
zzip_size_t l;
zzip_ssize_t rv;
if (! fp || ! fp->dir) return 0;
@ -358,14 +355,15 @@ zzip_file_read(ZZIP_FILE * fp, char * buf, int len)
do {
int err;
int startlen;
zzip_size_t startlen;
if (fp->crestlen > 0 && fp->d_stream.avail_in == 0)
{
int cl = fp->crestlen > ZZIP_32K ? ZZIP_32K : fp->crestlen;
/* int cl = fp->crestlen > 128? 128: fp->crestlen; */
zzip_size_t cl = ( fp->crestlen < ZZIP_32K ?
fp->crestlen : ZZIP_32K );
/* zzip_size_t cl = fp->crestlen > 128 ? 128 : fp->crestlen; */
int i = fp->io->read(dir->fd, fp->buf32k, cl);
zzip_ssize_t i = fp->io->read(dir->fd, fp->buf32k, cl);
if (i <= 0)
{
dir->errcode = ZZIP_DIR_READ; /* or ZZIP_DIR_READ_EOF ? */
@ -412,14 +410,14 @@ zzip_file_read(ZZIP_FILE * fp, char * buf, int len)
* perform a normal => read(2)-call, otherwise => zzip_file_read is called
* to decompress the data stream and any error is mapped to => errno(3).
*/
int
zzip_read(ZZIP_FILE * fp, char * buf, int len)
zzip_ssize_t
zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len)
{
if (! fp) return 0;
if (! fp->dir)
{ return fp->io->read(fp->fd, buf, len); } /* stat fd */
else
{ register int v;
{ register zzip_ssize_t v;
v = zzip_file_read(fp, buf, len);
if (v == -1) { errno = zzip_errno(fp->dir->errcode); }
return v;
@ -428,8 +426,8 @@ zzip_read(ZZIP_FILE * fp, char * buf, int len)
/** => zzip_read
*/
int
zzip_fread(void *ptr, int size, int nmemb, ZZIP_FILE *file)
zzip_size_t
zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, ZZIP_FILE *file)
{
if (! size) size=1;
return zzip_read (file, ptr, size*nmemb)/size;
@ -714,7 +712,7 @@ zzip_open_shared_io (ZZIP_FILE* stream,
/* see if we can share the same zip directory */
if (stream && stream->dir && stream->dir->realname)
{
int len = strlen (stream->dir->realname);
zzip_size_t len = strlen (stream->dir->realname);
if (! memcmp (filename, stream->dir->realname, len) &&
filename[len] == '/' && filename[len+1])
{
@ -864,10 +862,10 @@ zzip_rewind(ZZIP_FILE *fp)
* how gzio implements it, so I'm not sure there is a better way
* without using the internals of the algorithm.
*/
int
zzip_seek(ZZIP_FILE * fp, int offset, int whence)
zzip_off_t
zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence)
{
int cur_pos, rel_ofs, read_size, ofs;
zzip_off_t cur_pos, rel_ofs, read_size, ofs;
ZZIP_DIR *dir;
if (! fp)
@ -875,7 +873,7 @@ zzip_seek(ZZIP_FILE * fp, int offset, int whence)
if (! fp->dir)
{ /* stat fd */
return fp->io->seeks(fp->fd,offset,whence);
return fp->io->seeks(fp->fd, offset, whence);
}
cur_pos = zzip_tell(fp);
@ -914,7 +912,7 @@ zzip_seek(ZZIP_FILE * fp, int offset, int whence)
if (read_size < 0) /* bad offset, before beginning of file */
return -1;
if (read_size + cur_pos > fp->usize) /* bad offset, past EOF */
if (read_size + cur_pos > (zzip_off_t)fp->usize) /* bad offset, past EOF */
return -1;
if (read_size == 0) /* nothing to read */
@ -953,10 +951,10 @@ zzip_seek(ZZIP_FILE * fp, int offset, int whence)
while (read_size > 0)
{
int size = ZZIP_32K;
if (read_size < ZZIP_32K) size = (int)read_size;
zzip_off_t size = ZZIP_32K;
if (read_size < size/*32K*/) size = read_size;
size = zzip_file_read(fp, buf, size);
size = zzip_file_read(fp, buf, (zzip_size_t)size);
if (size <= 0) { free(buf); return -1; }
read_size -= size;
@ -979,7 +977,7 @@ zzip_seek(ZZIP_FILE * fp, int offset, int whence)
* calculated from the amount of data left and the total uncompressed
* size;
*/
int
zzip_off_t
zzip_tell(ZZIP_FILE * fp)
{
if (! fp)

@ -65,10 +65,10 @@ struct zzip_file
struct zzip_dir* dir;
int fd;
int method;
int restlen;
int crestlen;
int usize;
int csize;
zzip_size_t restlen;
zzip_size_t crestlen;
zzip_size_t usize;
zzip_size_t csize;
/* added dataoffset member - data offset from start of zipfile*/
zzip_off_t dataoffset;
char* buf32k;

@ -15,7 +15,6 @@
#include <zzip-io.h>
#include <string.h>
#include <sys/types.h> /* njh@bandsman.co.uk: for icc7.0 */
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>

@ -24,8 +24,11 @@
#include <sys/stat.h>
#endif
//#include "__mmap.h"
//#include "__debug.h"
#define __sizeof(X) ((zzip_ssize_t)(sizeof(X)))
/* per default, we use a little hack to correct bad z_rootseek parts */
#define ZZIP_CORRECT_ROOTSEEK 1
/* ------------------------- fetch helpers --------------------------------- */
@ -47,6 +50,86 @@ uint16_t __zzip_get16(unsigned char * s)
return ((uint16_t)s[1] << 8) | (uint16_t)s[0];
}
/* --------------------------- internals -------------------------------- */
/* internal functions of zziplib, avoid at all cost, changes w/o warning.
* we do export them for debugging purpose and special external tools
* which know what they do and which can adapt from version to version
*/
int __zzip_find_disk_trailer( int fd, zzip_off_t filesize,
struct zzip_disk_trailer * trailer,
zzip_plugin_io_t io);
int __zzip_parse_root_directory( int fd,
struct zzip_disk_trailer * trailer,
struct zzip_dir_hdr ** hdr_return,
zzip_plugin_io_t io);
_zzip_inline char* __zzip_aligned4(char* p);
/* ------------------------ harden routines ------------------------------ */
#ifdef ZZIP_HARDEN
/*
* check for inconsistent values in trailer and prefer lower seek value
* - we fix values assuming the root directory was written at the end
* and it is just before the zip trailer. Therefore, ...
*/
_zzip_inline static void __fixup_rootseek(
zzip_off_t offset_of_trailer,
struct zzip_disk_trailer* trailer)
{
if ( (zzip_off_t) ZZIP_GET32(trailer->z_rootseek) >
offset_of_trailer - (zzip_off_t) ZZIP_GET32(trailer->z_rootsize) &&
offset_of_trailer > (zzip_off_t) ZZIP_GET32(trailer->z_rootsize))
{
register zzip_off_t offset;
offset = offset_of_trailer - ZZIP_GET32(trailer->z_rootsize);
trailer->z_rootseek[0] = offset & 0xff;
trailer->z_rootseek[1] = offset >> 8 & 0xff;
trailer->z_rootseek[2] = offset >> 16 & 0xff;
trailer->z_rootseek[3] = offset >> 24 & 0xff;
}
}
#define __correct_rootseek(A,B,C)
#elif defined ZZIP_CORRECT_ROOTSEEK
/* store the seekvalue of the trailer into the "z_magic" field and with
* a 64bit off_t we overwrite z_disk/z_finaldisk as well. If you change
* anything in zziplib or dump the trailer structure then watch out that
* these are still unused, so that this code may still (ab)use those. */
#define __fixup_rootseek(_offset_of_trailer, _trailer) \
*(zzip_off_t*)_trailer = _offset_of_trailer;
#define __correct_rootseek( _u_rootseek, _u_rootsize, _trailer) \
if (_u_rootseek > *(zzip_off_t*)_trailer - _u_rootsize) \
_u_rootseek = *(zzip_off_t*)_trailer - _u_rootsize;
#else
#define __fixup_rootseek(A,B)
#define __correct_rootseek(A,B,C)
#endif
#ifdef DEBUG
_zzip_inline static void __debug_dir_hdr (struct zzip_dir_hdr* hdr)
{
if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_root_dirent))
{ WARN1("internal sizeof-mismatch may break wreakage"); }
/* the internal directory structure is never bigger than the
* external zip central directory space had been beforehand
* (as long as the following assertion holds...)
*/
if (((unsigned)hdr)&3)
{ NOTE1("this machine's malloc(3) returns sth. not u32-aligned"); }
/* we assume that if this machine's malloc has returned a non-aligned
* memory block, then it is actually safe to access misaligned data, and
* since it does only affect the first hdr it should not even bring about
* too much of that cpu's speed penalty
*/
}
#else
#define __debug_dir_hdr(X)
#endif
/* -------------------------- low-level interface -------------------------- */
#if defined BUFSIZ
@ -70,11 +153,7 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize,
struct zzip_disk_trailer * trailer,
zzip_plugin_io_t io)
{
#ifdef DEBUG
#define return(val) { e=val; goto cleanup; }
#else
#define return(val) { e=val; goto cleanup; }
#endif
register int e;
#ifndef _LOWSTK
@ -84,13 +163,13 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize,
char* buf = malloc(2*ZZIP_BUFSIZ);
#endif
zzip_off_t offset = 0;
size_t maplen = 0;
zzip_off_t maplen = 0; /* mmap(),read(),getpagesize() use size_t !! */
char* fd_map = 0;
if (!trailer)
{ return(EINVAL); }
if (filesize < sizeof(struct zzip_disk_trailer))
if (filesize < __sizeof(struct zzip_disk_trailer))
{ return(ZZIP_DIR_TOO_SHORT); }
if (!buf)
@ -99,8 +178,7 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize,
offset = filesize; /* a.k.a. old offset */
while(1) /* outer loop */
{
register unsigned char* p;
register unsigned char* s;
register unsigned char* mapped;
if (offset <= 0) { return(ZZIP_DIR_EDH_MISSING); }
@ -128,35 +206,40 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize,
if (io->seeks(fd, offset, SEEK_SET) < 0)
{ return(ZZIP_DIR_SEEK); }
if (io->read(fd, buf, maplen) < (long)maplen)
if (io->read(fd, buf, (zzip_size_t)maplen) < (zzip_ssize_t)maplen)
{ return(ZZIP_DIR_READ); }
p = buf; /* success */
mapped = buf; /* success */
/* now, check for the trailer-magic, hopefully near the end of file */
for (s = p + maplen-1; (s >= p); s--)
{
if (*s == 'P'
&& p+maplen-1-s > sizeof(*trailer)-2
&& ZZIP_DISK_TRAILER_CHECKMAGIC(s))
{
/* if the file-comment is not present, it happens
that the z_comment field often isn't either */
if (p+maplen-1-s > sizeof(*trailer))
{ memcpy (trailer, s, sizeof(*trailer)); }
else
{
memcpy (trailer, s, sizeof(*trailer)-2);
trailer->z_comment[0] = 0; trailer->z_comment[1] = 0;
}
{ return(0); }
}
{/* now, check for the trailer-magic, hopefully near the end of file */
register unsigned char* end = mapped + maplen;
register unsigned char* tail;
for (tail = end-1; (tail >= mapped); tail--)
{
if ((*tail == 'P') && /* quick pre-check for trailer magic */
end-tail >= __sizeof(*trailer)-2 &&
ZZIP_DISK_TRAILER_CHECKMAGIC(tail))
{
/* if the file-comment is not present, it happens
that the z_comment field often isn't either */
if (end-tail >= __sizeof(*trailer))
{
memcpy (trailer, tail, sizeof(*trailer));
}else{
memcpy (trailer, tail, sizeof(*trailer)-2);
trailer->z_comment[0] = 0;
trailer->z_comment[1] = 0;
}
__fixup_rootseek (offset + tail-mapped, trailer);
{ return(0); }
}
}
}
} /*outer loop*/
cleanup:
cleanup:
# ifdef _LOWSTK
free(buf);
# endif
@ -174,8 +257,8 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize,
_zzip_inline char* __zzip_aligned4(char* p)
{
#define aligned4 __zzip_aligned4
p += ((long)p)&1;
p += ((long)p)&2;
p += ((long)p)&1; /* warnings about truncation of a "pointer" */
p += ((long)p)&2; /* to a "long int" may be safely ignored :) */
return p;
}
@ -196,34 +279,19 @@ __zzip_parse_root_directory(int fd,
struct zzip_dir_hdr * hdr0;
uint16_t * p_reclen = 0;
short entries;
long offset;
char* fd_map = 0;
long offset; /* offset from start of root directory */
char* fd_map = 0;
int32_t fd_gap = 0;
uint16_t u_entries = ZZIP_GET16(trailer->z_entries);
uint32_t u_rootsize = ZZIP_GET32(trailer->z_rootsize);
uint32_t u_rootseek = ZZIP_GET32(trailer->z_rootseek);
__correct_rootseek (u_rootseek, u_rootsize, trailer);
hdr0 = (struct zzip_dir_hdr*) malloc(u_rootsize);
if (!hdr0)
return ZZIP_DIRSIZE;
hdr = hdr0;
hdr = hdr0; __debug_dir_hdr (hdr);
# ifdef DEBUG
if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_root_dirent))
{ WARN1("internal sizeof-mismatch may break wreakage"); }
/* the internal directory structure is never bigger than the
* external zip central directory space had been beforehand
* (as long as the following assertion holds...)
*/
if (((unsigned)hdr0)&3)
{ NOTE1("this machine's malloc(3) returns sth. not u32-aligned"); }
/* we assume that if this machine's malloc has returned a non-aligned
* memory block, then it is actually safe to access misaligned data, and
* since it does only affect the first hdr it should not even bring about
* too much of that cpu's speed penalty
*/
# endif
for (entries=u_entries, offset=0; entries > 0; entries--)
{
@ -236,11 +304,13 @@ __zzip_parse_root_directory(int fd,
{
if (io->seeks(fd, u_rootseek+offset, SEEK_SET) < 0)
return ZZIP_DIR_SEEK;
if (io->read(fd, &dirent, sizeof(dirent)) < sizeof(dirent))
if (io->read(fd, &dirent, sizeof(dirent)) < __sizeof(dirent))
return ZZIP_DIR_READ;
d = &dirent;
}
if (offset+sizeof(*d) > u_rootsize)
# if 0 && defined DEBUG
zzip_debug_xbuf ((unsigned char*) d, sizeof(*d) + 8);
# endif
@ -248,8 +318,7 @@ __zzip_parse_root_directory(int fd,
u_extras = ZZIP_GET16(d->z_extras);
u_comment = ZZIP_GET16(d->z_comment);
u_namlen = ZZIP_GET16(d->z_namlen);
/* writes over the read buffer, Since the structure where data is
copied is smaller than the data in buffer this can be done.
It is important that the order of setting the fields is considered
@ -264,10 +333,11 @@ __zzip_parse_root_directory(int fd,
hdr->d_compr = (uint8_t)ZZIP_GET16(d->z_compr);
if (hdr->d_compr > 255) hdr->d_compr = 255;
if (fd_map)
{ memcpy(hdr->d_name, fd_map+fd_gap+offset+sizeof(*d), u_namlen); }
else
{ io->read(fd, hdr->d_name, u_namlen); }
if (offset+sizeof(*d) + u_namlen > u_rootsize)
if (fd_map)
{ memcpy(hdr->d_name, fd_map+fd_gap+offset+sizeof(*d), u_namlen); }
else { io->read(fd, hdr->d_name, u_namlen); }
hdr->d_name[u_namlen] = '\0';
hdr->d_namlen = u_namlen;
@ -275,26 +345,25 @@ __zzip_parse_root_directory(int fd,
offset += sizeof(*d) + u_namlen + u_extras + u_comment;
if (offset > (long)u_rootsize)
break;
p_reclen = &hdr->d_reclen;
{ register char* p = (char*) hdr;
register char* q = aligned4 (p + sizeof(*hdr) + u_namlen + 1);
*p_reclen = q - p;
*p_reclen = (uint16_t)(q - p);
hdr = (struct zzip_dir_hdr*) q;
}
}/*for*/
if (!p_reclen)
return 0; /* 0 (sane) entries in zip directory... */
*p_reclen = 0; /* mark end of list */
if (hdr_return)
*hdr_return = hdr0;
if (p_reclen)
{
*p_reclen = 0; /* mark end of list */
return 0;
if (hdr_return)
*hdr_return = hdr0;
} /* else zero (sane) entries */
return (entries ? ZZIP_CORRUPTED : 0);
}
/* ------------------------- high-level interface ------------------------- */
@ -451,7 +520,6 @@ __zzip_dir_parse (ZZIP_DIR* dir)
dir->io)) != 0)
{ goto error; }
if ( (rv = __zzip_parse_root_directory(dir->fd, &trailer, &dir->hdr0,
dir->io)) != 0)
{ goto error; }
@ -470,7 +538,7 @@ __zzip_try_open(zzip_char_t* filename, int filemode,
{
auto char file[PATH_MAX];
int fd;
int len = strlen (filename);
zzip_size_t len = strlen (filename);
if (len+4 >= PATH_MAX) return -1;
memcpy(file, filename, len+1);

@ -75,6 +75,9 @@ ZZIP_DIR*
zzip_dir_fdopen_ext_io(int fd, zzip_error_t * errorcode_p,
zzip_strings_t* ext, const zzip_plugin_io_t io);
ZZIP_DIR* /*depracated*/
zzip_dir_alloc_ext_io (zzip_strings_t* ext, const zzip_plugin_io_t io);
/* get 16/32 bits from little-endian zip-file to host byteorder */
uint32_t __zzip_get32(unsigned char * s);
uint16_t __zzip_get16(unsigned char * s);

@ -3,12 +3,17 @@
* Guido Draheim <guidod@gmx.de>
* Tomi Ollila <Tomi.Ollila@iki.fi>
*
* Copyright (c) 1999,2000,2001,2002 Guido Draheim
* Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
* All rights reserved,
* usage allowed under the restrictions of the
* Lesser GNU General Public License
* note the additional license information
* that can be found in COPYING.ZZIP
*
* if you see "unknown symbol" errors, check first that `-I ..` is part of
* your compiler options - a special hint to VC/IDE users who tend to make up
* their own workspace files. All includes look like #include <zzip|*.h>, so
* you need to add an include path to the dir containing (!!) the ./zzip/ dir
*/
#ifndef _ZZIP_ZZIP_H /* zziplib.h */
@ -17,6 +22,8 @@
#include <zzip-conf.h>
#include <fcntl.h>
#include <stddef.h> /* size_t and friends */
/* msvc6 has neither ssize_t (we assume "int") nor off_t (assume "long") */
#ifdef __cplusplus
extern "C" {
@ -72,6 +79,8 @@ typedef enum
typedef char _zzip_const * _zzip_const zzip_strings_t;
typedef char _zzip_const zzip_char_t;
typedef _zzip_off_t zzip_off_t;
typedef _zzip_size_t zzip_size_t;
typedef _zzip_ssize_t zzip_ssize_t;
typedef struct zzip_dir ZZIP_DIR;
typedef struct zzip_file ZZIP_FILE;
typedef struct zzip_dirent ZZIP_DIRENT;
@ -173,14 +182,14 @@ ZZIP_FILE * zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int modes);
_zzip_export
int zzip_file_close(ZZIP_FILE * fp);
_zzip_export
int zzip_file_read(ZZIP_FILE * fp, char* buf, int len);
zzip_ssize_t zzip_file_read(ZZIP_FILE * fp, char* buf, zzip_size_t len);
_zzip_export
ZZIP_FILE * zzip_open(zzip_char_t* name, int flags);
_zzip_export
int zzip_close(ZZIP_FILE * fp);
_zzip_export
int zzip_read(ZZIP_FILE * fp, char * buf, int len);
zzip_ssize_t zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len);
_zzip_export
@ -188,7 +197,8 @@ ZZIP_FILE* zzip_freopen(zzip_char_t* name, zzip_char_t* mode, ZZIP_FILE*);
_zzip_export
ZZIP_FILE* zzip_fopen(zzip_char_t* name, zzip_char_t* mode);
_zzip_export
int zzip_fread(void *ptr, int size, int nmemb, ZZIP_FILE *file);
zzip_size_t zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb,
ZZIP_FILE * file);
_zzip_export
int zzip_fclose(ZZIP_FILE * fp);
@ -198,10 +208,9 @@ int zzip_fclose(ZZIP_FILE * fp);
_zzip_export
int zzip_rewind(ZZIP_FILE *fp);
_zzip_export
int zzip_seek(ZZIP_FILE * fp, int offset, int
whence);
zzip_off_t zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence);
_zzip_export
int zzip_tell(ZZIP_FILE * fp);
zzip_off_t zzip_tell(ZZIP_FILE * fp);
/*

@ -4,7 +4,7 @@
# Created: 1993-05-16
# Public domain
# $Id: mkinstalldirs,v 1.2 2003/08/02 22:37:52 kojm Exp $
# $Id: mkinstalldirs,v 1.3 2003/08/03 22:25:30 kojm Exp $
errstatus=0
dirmode=""

Loading…
Cancel
Save