win32: enable 64-bit file lengths
[platform/upstream/libwebsockets.git] / lib / fops-zip.c
index 02f4999..45818c7 100644 (file)
@@ -147,6 +147,7 @@ enum {
        LWS_FZ_ERR_CENTRAL_READ,
        LWS_FZ_ERR_CENTRAL_SANITY,
        LWS_FZ_ERR_NAME_TOO_LONG,
+       LWS_FZ_ERR_NAME_SEEK,
        LWS_FZ_ERR_NAME_READ,
        LWS_FZ_ERR_CONTENT_SANITY,
        LWS_FZ_ERR_CONTENT_SEEK,
@@ -177,7 +178,7 @@ int
 lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len)
 {
        lws_filepos_t amount;
-       uint8_t buf[64];
+       uint8_t buf[96];
        int i;
 
        if (lws_vfs_file_seek_end(priv->zip_fop_fd, -ZE_DIRECTORY_LENGTH) < 0)
@@ -223,7 +224,7 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len)
                if (get_u32(buf + ZC_SIGNATURE) != 0x02014B50)
                        return LWS_FZ_ERR_CENTRAL_SANITY;
 
-               lwsl_debug("cstart 0x%lx\n", priv->content_start);
+               lwsl_debug("cstart 0x%lx\n", (unsigned long)priv->content_start);
 
                priv->hdr.filename_len = get_u16(buf + ZC_FILE_NAME_LENGTH);
                priv->hdr.extra = get_u16(buf + ZC_EXTRA_FIELD_LENGTH);
@@ -256,7 +257,8 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len)
                        goto next;
 
                /* we found a match */
-               lws_vfs_file_seek_set(priv->zip_fop_fd, priv->hdr.offset);
+               if (lws_vfs_file_seek_set(priv->zip_fop_fd, priv->hdr.offset) < 0)
+                       return LWS_FZ_ERR_NAME_SEEK;
                if (priv->zip_fop_fd->fops->LWS_FOP_READ(priv->zip_fop_fd,
                                                        &amount, buf,
                                                        ZL_HEADER_LENGTH))
@@ -270,7 +272,7 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len)
                                      get_u16(buf + ZL_REL_OFFSET_CONTENT);
 
                lwsl_debug("content supposed to start at 0x%lx\n",
-                          priv->content_start);
+                          (unsigned long)priv->content_start);
 
                if (priv->content_start > priv->zip_fop_fd->len)
                        return LWS_FZ_ERR_CONTENT_SANITY;
@@ -533,7 +535,7 @@ lws_fops_zip_read(lws_fop_fd_t fd, lws_filepos_t *amount, uint8_t *buf,
                        *amount = 0;
                }
 
-               priv->inflate.avail_out = len;
+               priv->inflate.avail_out = (unsigned int)len;
                priv->inflate.next_out = buf;
 
 spin:
@@ -552,7 +554,7 @@ spin:
 
                        cur += ramount;
 
-                       priv->inflate.avail_in = ramount;
+                       priv->inflate.avail_in = (unsigned int)ramount;
                        priv->inflate.next_in = priv->rbuf;
                }
 
@@ -594,7 +596,7 @@ spin:
                        if (rlen > len)
                                rlen = len;
                        /* provide stuff from canned header */
-                       memcpy(buf, hd + fd->pos, rlen);
+                       memcpy(buf, hd + fd->pos, (size_t)rlen);
                        fd->pos += rlen;
                        buf += rlen;
                        len -= rlen;
@@ -634,7 +636,7 @@ spin:
                        if (rlen > len)
                                rlen = len;
 
-                       memcpy(buf, priv->u.trailer8 + cur, rlen);
+                       memcpy(buf, priv->u.trailer8 + cur, (size_t)rlen);
 
                        *amount += rlen;
                        fd->pos += rlen;