Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use old read/write logic for large files.
Vsevolod Stakhov committed 13 years ago
commit 41df825b0dd77336e1b2a302c02e1e95de25b228
parent d6c9f1d
1 file changed +31 -7
modified libpkg/packing.c
@@ -35,6 +35,7 @@
#include <fts.h>
#include <string.h>
#include <sys/mman.h>
+
#include <limits.h>

#include "pkg.h"
#include "private/event.h"
@@ -207,16 +208,39 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
			retcode = EPKG_FATAL;
			goto cleanup;
		}
-
		if ((map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) != MAP_FAILED) {
+
		if (st.st_size > SIZE_T_MAX) {
+
			char buf[BUFSIZ];
+
			int len;
+

+
			while ((len = read(fd, buf, sizeof(buf))) > 0)
+
				if (archive_write_data(pack->awrite, buf, len) == -1) {
+
					pkg_emit_errno("archive_write_data", "archive write error");
+
					retcode = EPKG_FATAL;
+
					break;
+
				}
+

+
			if (len == -1) {
+
				pkg_emit_errno("read", "file read error");
+
				retcode = EPKG_FATAL;
+
			}
			close(fd);
-
			archive_write_data(pack->awrite, map, st.st_size);
-
			munmap(map, st.st_size);
		}
		else {
-
			close(fd);
-
			pkg_emit_errno("open", filepath);
-
			retcode = EPKG_FATAL;
-
			goto cleanup;
+
			if ((map = mmap(NULL, st.st_size, PROT_READ,
+
					MAP_SHARED, fd, 0)) != MAP_FAILED) {
+
				close(fd);
+
				if (archive_write_data(pack->awrite, map, st.st_size) == -1) {
+
					pkg_emit_errno("archive_write_data", "archive write error");
+
					retcode = EPKG_FATAL;
+
				}
+
				munmap(map, st.st_size);
+
			}
+
			else {
+
				close(fd);
+
				pkg_emit_errno("open", filepath);
+
				retcode = EPKG_FATAL;
+
				goto cleanup;
+
			}
		}
	}