7z: Make error handling a little more robust.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1689 1dc6e265fefc
child 1692 acdcf93d1f9b
7z: Make error handling a little more robust.
src/physfs_archiver_7z.c
--- a/src/physfs_archiver_7z.c	Sun May 17 01:26:31 2020 -0400
+++ b/src/physfs_archiver_7z.c	Sun May 17 01:41:52 2020 -0400
@@ -285,13 +285,16 @@
                         &blockIndex, &outBuffer, &outBufferSize, &offset,
                         &outSizeProcessed, alloc, alloc);
     GOTO_IF(rc != SZ_OK, szipErrorCode(rc), SZIP_openRead_failed);
+    GOTO_IF(outBuffer == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
 
     io->destroy(io);
     io = NULL;
 
-    buf = allocator.Malloc(outSizeProcessed);
+    buf = allocator.Malloc(outSizeProcessed ? outSizeProcessed : 1);
     GOTO_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, SZIP_openRead_failed);
-    memcpy(buf, outBuffer + offset, outSizeProcessed);
+
+    if (outSizeProcessed > 0)
+        memcpy(buf, outBuffer + offset, outSizeProcessed);
 
     alloc->Free(alloc, outBuffer);
     outBuffer = NULL;