[gcab/wip/hughsie/covscan: 1/3] Detect errors when decompressing MSZIP archives
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcab/wip/hughsie/covscan: 1/3] Detect errors when decompressing MSZIP archives
- Date: Wed, 13 Apr 2022 12:50:23 +0000 (UTC)
commit 60e12d9f7198b34cc710ddf89f94930ba1606184
Author: Richard Hughes <richard hughsie com>
Date: Wed Apr 13 13:41:38 2022 +0100
Detect errors when decompressing MSZIP archives
libgcab/cabinet.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/libgcab/cabinet.c b/libgcab/cabinet.c
index 53d58bb..6a7ce99 100644
--- a/libgcab/cabinet.c
+++ b/libgcab/cabinet.c
@@ -35,7 +35,7 @@ zfree (voidpf opaque, voidpf address)
}
static gboolean
-cdata_set (cdata_t *cd, int type, guint8 *data, size_t size)
+cdata_set (cdata_t *cd, int type, guint8 *data, size_t size, GError **error)
{
if (type > GCAB_COMPRESSION_MSZIP) {
g_critical ("unsupported compression method %d", type);
@@ -51,11 +51,16 @@ cdata_set (cdata_t *cd, int type, guint8 *data, size_t size)
if (type == GCAB_COMPRESSION_MSZIP) {
z_stream stream = { 0, };
+ int zret;
stream.zalloc = zalloc;
stream.zfree = zfree;
- if (deflateInit2 (&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
+ zret = deflateInit2 (&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
+ if (zret != Z_OK) {
+ g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
+ "zlib deflateInit2 failed: %s", zError (zret));
return FALSE;
+ }
stream.next_in = data;
stream.avail_in = size;
stream.next_out = cd->in + 2;
@@ -63,7 +68,12 @@ cdata_set (cdata_t *cd, int type, guint8 *data, size_t size)
/* insert the signature */
cd->in[0] = 'C';
cd->in[1] = 'K';
- deflate (&stream, Z_FINISH);
+ zret = deflate (&stream, Z_FINISH);
+ if (zret != Z_OK && zret != Z_STREAM_END) {
+ g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
+ "zlib deflate failed: %s", zError (zret));
+ return FALSE;
+ }
deflateEnd (&stream);
cd->ncbytes = stream.total_out + 2;
}
@@ -468,7 +478,7 @@ cdata_write (cdata_t *cd, GDataOutputStream *out, int type,
guint8 *data, size_t size, gsize *bytes_written,
GCancellable *cancellable, GError **error)
{
- if (!cdata_set(cd, type, data, size))
+ if (!cdata_set(cd, type, data, size, error))
return FALSE;
guint32 datacsum = compute_checksum(cd->in, cd->ncbytes, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]