Skip to content

Commit ac88119

Browse files
authored
Fix overallocation of stack in NOZUtils
iOS cannot handle a 1MB stack allocation, move to heap allocation instead
1 parent 74d13c4 commit ac88119

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ZipUtilities/NOZUtils.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ BOOL NOZEncodeFile(NSString *sourceFile,
222222

223223
do {
224224
const size_t bufferSize = 1024 * 1024;
225-
Byte buffer[bufferSize];
225+
Byte *buffer = malloc(bufferSize * sizeof(Byte));
226+
noz_defer(^{
227+
free(buffer);
228+
});
226229
while (!feof(uncompressedFile)) {
227230

228231
const size_t bytesRead = fread(buffer, 1, bufferSize, uncompressedFile);
@@ -321,7 +324,10 @@ BOOL NOZDecodeFile(NSString *sourceFile,
321324

322325
do {
323326
const size_t bufferSize = 1024 * 1024;
324-
Byte buffer[bufferSize];
327+
Byte *buffer = malloc(bufferSize * sizeof(Byte));
328+
noz_defer(^{
329+
free(buffer);
330+
});
325331
while (!context.hasFinished) {
326332
const size_t bytesRead = fread(buffer, 1, bufferSize, compressedFile);
327333
if (ferror(compressedFile)) {

0 commit comments

Comments
 (0)