summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-13 13:37:42 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-16 09:34:35 +0200
commitf757737060d4daebb24a32e90d912661428708a8 (patch)
treea6e96145d4fc540e435c13a69c924329db2edb6d
parentc1a2cb729bd5bb5fdadf00cb3968bbc541f79750 (diff)
Remodel libtar/tar2sqfs to read data from an istream_t
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--bin/tar2sqfs/Makemodule.am2
-rw-r--r--bin/tar2sqfs/process_tarball.c81
-rw-r--r--bin/tar2sqfs/tar2sqfs.c18
-rw-r--r--bin/tar2sqfs/tar2sqfs.h7
-rw-r--r--include/common.h3
-rw-r--r--include/tar.h15
-rw-r--r--lib/common/Makemodule.am4
-rw-r--r--lib/common/io_stdin.c182
-rw-r--r--lib/tar/Makemodule.am5
-rw-r--r--lib/tar/internal.h8
-rw-r--r--lib/tar/pax_header.c2
-rw-r--r--lib/tar/read_header.c24
-rw-r--r--lib/tar/read_retry.c57
-rw-r--r--lib/tar/read_sparse_map_new.c20
-rw-r--r--lib/tar/read_sparse_map_old.c14
-rw-r--r--lib/tar/record_to_memory.c40
-rw-r--r--lib/tar/skip.c44
-rw-r--r--tests/Makemodule.am60
-rw-r--r--tests/tar_big_file.c7
-rw-r--r--tests/tar_fuzz.c14
-rw-r--r--tests/tar_simple.c9
-rw-r--r--tests/tar_sparse.c7
-rw-r--r--tests/tar_sparse_gnu.c7
-rw-r--r--tests/tar_target_filled.c11
-rw-r--r--tests/tar_xattr.c9
-rw-r--r--tests/tar_xattr_bin.c9
26 files changed, 238 insertions, 421 deletions
diff --git a/bin/tar2sqfs/Makemodule.am b/bin/tar2sqfs/Makemodule.am
index 16bec99..0a74419 100644
--- a/bin/tar2sqfs/Makemodule.am
+++ b/bin/tar2sqfs/Makemodule.am
@@ -1,7 +1,7 @@
tar2sqfs_SOURCES = bin/tar2sqfs/tar2sqfs.c bin/tar2sqfs/tar2sqfs.h
tar2sqfs_SOURCES += bin/tar2sqfs/options.c bin/tar2sqfs/process_tarball.c
tar2sqfs_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
-tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a
+tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a libfstream.a
tar2sqfs_LDADD += libfstree.a libcompat.a libfstree.a $(LZO_LIBS)
tar2sqfs_LDADD += $(PTHREAD_LIBS)
diff --git a/bin/tar2sqfs/process_tarball.c b/bin/tar2sqfs/process_tarball.c
index 415e362..4d7f0a1 100644
--- a/bin/tar2sqfs/process_tarball.c
+++ b/bin/tar2sqfs/process_tarball.c
@@ -6,28 +6,74 @@
*/
#include "tar2sqfs.h"
-static int write_file(FILE *input_file, sqfs_writer_t *sqfs,
+static int write_file(istream_t *input_file, sqfs_writer_t *sqfs,
const tar_header_decoded_t *hdr,
file_info_t *fi, sqfs_u64 filesize)
{
- sqfs_file_t *file;
- int flags;
- int ret;
+ const sparse_map_t *list;
+ int flags = 0, ret = 0;
+ sqfs_u64 offset, diff;
+ bool sparse_region;
+ ostream_t *out;
- file = sqfs_get_stdin_file(input_file, hdr->sparse, filesize);
- if (file == NULL) {
- perror("packing files");
- return -1;
- }
-
- flags = 0;
if (no_tail_pack && filesize > cfg.block_size)
flags |= SQFS_BLK_DONT_FRAGMENT;
- ret = write_data_from_file(hdr->name, sqfs->data,
- (sqfs_inode_generic_t **)&fi->user_ptr,
- file, flags);
- sqfs_destroy(file);
+ out = data_writer_ostream_create(hdr->name, sqfs->data,
+ (sqfs_inode_generic_t **)&fi->user_ptr,
+ flags);
+
+ if (out == NULL)
+ return -1;
+
+ list = hdr->sparse;
+
+ for (offset = 0; offset < filesize; offset += diff) {
+ if (hdr->sparse != NULL) {
+ if (list == NULL) {
+ sparse_region = true;
+ diff = filesize - offset;
+ } else if (offset < list->offset) {
+ sparse_region = true;
+ diff = list->offset - offset;
+ } else if (offset - list->offset >= list->count) {
+ list = list->next;
+ diff = 0;
+ continue;
+ } else {
+ sparse_region = false;
+ diff = list->count - (offset - list->offset);
+ }
+ } else {
+ sparse_region = false;
+ diff = filesize - offset;
+ }
+
+ if (sizeof(diff) > sizeof(size_t) && diff > 0x7FFFFFFFUL)
+ diff = 0x7FFFFFFFUL;
+
+ if (sparse_region) {
+ ret = ostream_append_sparse(out, diff);
+ } else {
+ ret = ostream_append_from_istream(out, input_file,
+ diff);
+
+ if (ret == 0) {
+ fprintf(stderr, "%s: unexpected end-of-file\n",
+ hdr->name);
+ ret = -1;
+ } else if (ret > 0) {
+ diff = ret;
+ ret = 0;
+ }
+ }
+
+ if (ret < 0)
+ break;
+ }
+
+ ostream_flush(out);
+ sqfs_destroy(out);
if (ret)
return -1;
@@ -78,7 +124,8 @@ static int copy_xattr(sqfs_writer_t *sqfs, tree_node_t *node,
return 0;
}
-static int create_node_and_repack_data(FILE *input_file, sqfs_writer_t *sqfs,
+static int create_node_and_repack_data(istream_t *input_file,
+ sqfs_writer_t *sqfs,
tar_header_decoded_t *hdr)
{
tree_node_t *node;
@@ -149,7 +196,7 @@ static int set_root_attribs(sqfs_writer_t *sqfs,
return 0;
}
-int process_tarball(FILE *input_file, sqfs_writer_t *sqfs)
+int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs)
{
bool skip, is_root, is_prefixed;
tar_header_decoded_t hdr;
diff --git a/bin/tar2sqfs/tar2sqfs.c b/bin/tar2sqfs/tar2sqfs.c
index ae56e6b..6cab231 100644
--- a/bin/tar2sqfs/tar2sqfs.c
+++ b/bin/tar2sqfs/tar2sqfs.c
@@ -9,26 +9,18 @@
int main(int argc, char **argv)
{
int status = EXIT_FAILURE;
- FILE *input_file = NULL;
+ istream_t *input_file = NULL;
sqfs_writer_t sqfs;
process_args(argc, argv);
-#ifdef _WIN32
- _setmode(_fileno(stdin), _O_BINARY);
- input_file = stdin;
-#else
- input_file = freopen(NULL, "rb", stdin);
-#endif
-
- if (input_file == NULL) {
- perror("changing stdin to binary mode");
+ input_file = istream_open_stdin();
+ if (input_file == NULL)
return EXIT_FAILURE;
- }
memset(&sqfs, 0, sizeof(sqfs));
if (sqfs_writer_init(&sqfs, &cfg))
- return EXIT_FAILURE;
+ goto out_if;
if (process_tarball(input_file, &sqfs))
goto out;
@@ -42,5 +34,7 @@ int main(int argc, char **argv)
status = EXIT_SUCCESS;
out:
sqfs_writer_cleanup(&sqfs, status);
+out_if:
+ sqfs_destroy(input_file);
return status;
}
diff --git a/bin/tar2sqfs/tar2sqfs.h b/bin/tar2sqfs/tar2sqfs.h
index a27a50b..d127aa0 100644
--- a/bin/tar2sqfs/tar2sqfs.h
+++ b/bin/tar2sqfs/tar2sqfs.h
@@ -16,11 +16,6 @@
#include <getopt.h>
#include <string.h>
#include <stdio.h>
-#include <fcntl.h>
-
-#ifdef _WIN32
-#include <io.h>
-#endif
/* options.c */
extern bool dont_skip;
@@ -32,6 +27,6 @@ extern char *root_becomes;
void process_args(int argc, char **argv);
/* process_tarball.c */
-int process_tarball(FILE *input_file, sqfs_writer_t *sqfs);
+int process_tarball(istream_t *input_file, sqfs_writer_t *sqfs);
#endif /* TAR2SQFS_H */
diff --git a/include/common.h b/include/common.h
index 8639558..ea27edc 100644
--- a/include/common.h
+++ b/include/common.h
@@ -114,9 +114,6 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data,
const sqfs_inode_generic_t *inode,
ostream_t *fp, size_t block_size);
-sqfs_file_t *sqfs_get_stdin_file(FILE *fp, const sparse_map_t *map,
- sqfs_u64 size);
-
int write_data_from_file(const char *filename, sqfs_block_processor_t *data,
sqfs_inode_generic_t **inode,
sqfs_file_t *file, int flags);
diff --git a/include/tar.h b/include/tar.h
index 38ec656..10e7b52 100644
--- a/include/tar.h
+++ b/include/tar.h
@@ -131,12 +131,12 @@ int write_hard_link(ostream_t *fp, const struct stat *sb, const char *name,
const char *target, unsigned int counter);
/* calcuate and skip the zero padding */
-int skip_padding(FILE *fp, sqfs_u64 size);
+int skip_padding(istream_t *fp, sqfs_u64 size);
/* round up to block size and skip the entire entry */
-int skip_entry(FILE *fp, sqfs_u64 size);
+int skip_entry(istream_t *fp, sqfs_u64 size);
-int read_header(FILE *fp, tar_header_decoded_t *out);
+int read_header(istream_t *fp, tar_header_decoded_t *out);
void free_xattr_list(tar_xattr_t *list);
@@ -148,13 +148,4 @@ void clear_header(tar_header_decoded_t *hdr);
*/
int padd_file(ostream_t *fp, sqfs_u64 size);
-
-/*
- A wrapper around the read() system call. It retries the read if it is
- interrupted by a signal or less than the desired size was read. Returns 0
- on success. Writes to stderr on failure using 'errstr' as a perror style
- error prefix.
-*/
-int read_retry(const char *errstr, FILE *fp, void *buffer, size_t size);
-
#endif /* TAR_H */
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index df08894..e191e29 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -3,10 +3,10 @@ libcommon_a_SOURCES += lib/common/inode_stat.c lib/common/hardlink.c
libcommon_a_SOURCES += lib/common/print_version.c lib/common/data_reader_dump.c
libcommon_a_SOURCES += lib/common/compress.c lib/common/comp_opt.c
libcommon_a_SOURCES += lib/common/data_writer.c include/common.h
-libcommon_a_SOURCES += lib/common/get_path.c lib/common/io_stdin.c
+libcommon_a_SOURCES += lib/common/get_path.c lib/common/data_writer_ostream.c
libcommon_a_SOURCES += lib/common/writer.c lib/common/perror.c
libcommon_a_SOURCES += lib/common/mkdir_p.c lib/common/parse_size.c
-libcommon_a_SOURCES += lib/common/print_size.c lib/common/data_writer_ostream.c
+libcommon_a_SOURCES += lib/common/print_size.c
libcommon_a_CFLAGS = $(AM_CFLAGS) $(LZO_CFLAGS)
if WITH_LZO
diff --git a/lib/common/io_stdin.c b/lib/common/io_stdin.c
deleted file mode 100644
index 4694989..0000000
--- a/lib/common/io_stdin.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * io_stdin.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "common.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-
-typedef struct {
- sqfs_file_t base;
-
- const sparse_map_t *map;
- sqfs_u64 offset;
- sqfs_u64 real_size;
- sqfs_u64 apparent_size;
- FILE *fp;
-} sqfs_file_stdinout_t;
-
-
-static void stdinout_destroy(sqfs_object_t *base)
-{
- free(base);
-}
-
-static sqfs_u64 stdinout_get_size(const sqfs_file_t *base)
-{
- return ((const sqfs_file_stdinout_t *)base)->apparent_size;
-}
-
-static int stdinout_truncate(sqfs_file_t *base, sqfs_u64 size)
-{
- (void)base; (void)size;
- return SQFS_ERROR_IO;
-}
-
-static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset,
- void *buffer, size_t size)
-{
- sqfs_file_stdinout_t *file = (sqfs_file_stdinout_t *)base;
- size_t temp_size = 0;
- sqfs_u8 *temp = NULL;
- sqfs_u64 diff;
- size_t ret;
-
- if (offset < file->offset)
- return SQFS_ERROR_IO;
-
- if (offset > file->offset) {
- temp_size = 1024;
- temp = alloca(temp_size);
- }
-
- if (offset >= file->real_size || (offset + size) > file->real_size)
- return SQFS_ERROR_OUT_OF_BOUNDS;
-
- while (size > 0) {
- if (ferror(file->fp))
- return SQFS_ERROR_IO;
-
- if (feof(file->fp))
- return SQFS_ERROR_OUT_OF_BOUNDS;
-
- if (offset > file->offset) {
- diff = file->offset - offset;
- diff = diff > (sqfs_u64)temp_size ? temp_size : diff;
-
- ret = fread(temp, 1, diff, file->fp);
- } else {
- ret = fread(buffer, 1, size, file->fp);
- }
-
- if (offset <= file->offset) {
- buffer = (char *)buffer + ret;
- size -= ret;
- offset += ret;
- }
-
- file->offset += ret;
- }
-
- return 0;
-}
-
-static int stdin_read_condensed(sqfs_file_t *base, sqfs_u64 offset,
- void *buffer, size_t size)
-{
- sqfs_file_stdinout_t *file = (sqfs_file_stdinout_t *)base;
- sqfs_u64 poffset = 0, src_start;
- size_t dst_start, diff, count;
- const sparse_map_t *it;
- int err;
-
- memset(buffer, 0, size);
-
- for (it = file->map; it != NULL; it = it->next) {
- if (it->offset + it->count <= offset) {
- poffset += it->count;
- continue;
- }
-
- if (it->offset >= offset + size) {
- poffset += it->count;
- continue;
- }
-
- count = size;
-
- if (offset + count >= it->offset + it->count)
- count = it->offset + it->count - offset;
-
- if (it->offset < offset) {
- diff = offset - it->offset;
-
- src_start = poffset + diff;
- dst_start = 0;
- count -= diff;
- } else if (it->offset > offset) {
- diff = it->offset - offset;
-
- src_start = poffset;
- dst_start = diff;
- } else {
- src_start = poffset;
- dst_start = 0;
- }
-
- err = stdin_read_at(base, src_start,
- (char *)buffer + dst_start, count);
- if (err)
- return err;
-
- poffset += it->count;
- }
-
- return 0;
-}
-
-static int stdin_write_at(sqfs_file_t *base, sqfs_u64 offset,
- const void *buffer, size_t size)
-{
- (void)base; (void)offset; (void)buffer; (void)size;
- return SQFS_ERROR_IO;
-}
-
-sqfs_file_t *sqfs_get_stdin_file(FILE *fp, const sparse_map_t *map,
- sqfs_u64 size)
-{
- sqfs_file_stdinout_t *file = calloc(1, sizeof(*file));
- sqfs_file_t *base = (sqfs_file_t *)file;
- const sparse_map_t *it;
-
- if (file == NULL)
- return NULL;
-
- file->apparent_size = size;
- file->map = map;
- file->fp = fp;
-
- if (map != NULL) {
- for (it = map; it != NULL; it = it->next)
- file->real_size += map->count;
- } else {
- file->real_size = size;
- }
-
- ((sqfs_object_t *)base)->destroy = stdinout_destroy;
- base->write_at = stdin_write_at;
- base->get_size = stdinout_get_size;
- base->truncate = stdinout_truncate;
-
- if (map == NULL) {
- base->read_at = stdin_read_at;
- } else {
- base->read_at = stdin_read_condensed;
- }
- return base;
-}
diff --git a/lib/tar/Makemodule.am b/lib/tar/Makemodule.am
index 7ba0454..414aca1 100644
--- a/lib/tar/Makemodule.am
+++ b/lib/tar/Makemodule.am
@@ -1,9 +1,10 @@
-libtar_a_SOURCES = lib/tar/read_header.c lib/tar/write_header.c lib/tar/skip.c
+libtar_a_SOURCES = lib/tar/read_header.c lib/tar/write_header.c
libtar_a_SOURCES += lib/tar/number.c lib/tar/checksum.c lib/tar/cleanup.c
libtar_a_SOURCES += lib/tar/read_sparse_map.c lib/tar/read_sparse_map_old.c
libtar_a_SOURCES += lib/tar/base64.c lib/tar/urldecode.c lib/tar/internal.h
-libtar_a_SOURCES += lib/tar/padd_file.c lib/tar/read_retry.c include/tar.h
+libtar_a_SOURCES += lib/tar/padd_file.c lib/tar/record_to_memory.c
libtar_a_SOURCES += lib/tar/pax_header.c lib/tar/read_sparse_map_new.c
+libtar_a_SOURCES += include/tar.h
libtar_a_CFLAGS = $(AM_CFLAGS)
libtar_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/lib/tar/internal.h b/lib/tar/internal.h
index bea863d..b7c4c34 100644
--- a/lib/tar/internal.h
+++ b/lib/tar/internal.h
@@ -59,9 +59,9 @@ bool is_checksum_valid(const tar_header_t *hdr);
sparse_map_t *read_sparse_map(const char *line);
-sparse_map_t *read_gnu_old_sparse(FILE *fp, tar_header_t *hdr);
+sparse_map_t *read_gnu_old_sparse(istream_t *fp, tar_header_t *hdr);
-sparse_map_t *read_gnu_new_sparse(FILE *fp, tar_header_decoded_t *out);
+sparse_map_t *read_gnu_new_sparse(istream_t *fp, tar_header_decoded_t *out);
void free_sparse_list(sparse_map_t *sparse);
@@ -69,9 +69,9 @@ size_t base64_decode(sqfs_u8 *out, const char *in, size_t len);
void urldecode(char *str);
-char *record_to_memory(FILE *fp, sqfs_u64 size);
+char *record_to_memory(istream_t *fp, size_t size);
-int read_pax_header(FILE *fp, sqfs_u64 entsize, unsigned int *set_by_pax,
+int read_pax_header(istream_t *fp, sqfs_u64 entsize, unsigned int *set_by_pax,
tar_header_decoded_t *out);
#endif /* INTERNAL_H */
diff --git a/lib/tar/pax_header.c b/lib/tar/pax_header.c
index 448976d..a96a32f 100644
--- a/lib/tar/pax_header.c
+++ b/lib/tar/pax_header.c
@@ -25,7 +25,7 @@ static tar_xattr_t *mkxattr(const char *key, size_t keylen,
return xattr;
}
-int read_pax_header(FILE *fp, sqfs_u64 entsize, unsigned int *set_by_pax,
+int read_pax_header(istream_t *fp, sqfs_u64 entsize, unsigned int *set_by_pax,
tar_header_decoded_t *out)
{
char *buffer, *line, *key, *ptr, *value, *end;
diff --git a/lib/tar/read_header.c b/lib/tar/read_header.c
index 14752ea..b332514 100644
--- a/lib/tar/read_header.c
+++ b/lib/tar/read_header.c
@@ -170,20 +170,24 @@ static int decode_header(const tar_header_t *hdr, unsigned int set_by_pax,
return 0;
}
-int read_header(FILE *fp, tar_header_decoded_t *out)
+int read_header(istream_t *fp, tar_header_decoded_t *out)
{
unsigned int set_by_pax = 0;
bool prev_was_zero = false;
sqfs_u64 pax_size;
tar_header_t hdr;
- int version;
+ int version, ret;
memset(out, 0, sizeof(*out));
for (;;) {
- if (read_retry("reading tar header", fp, &hdr, sizeof(hdr)))
+ ret = istream_read(fp, &hdr, sizeof(hdr));
+ if (ret < 0)
goto fail;
+ if ((size_t)ret < sizeof(hdr))
+ goto out_eof;
+
if (is_zero_block(&hdr)) {
if (prev_was_zero)
goto out_eof;
@@ -294,3 +298,17 @@ fail:
clear_header(out);
return -1;
}
+
+int skip_padding(istream_t *fp, sqfs_u64 size)
+{
+ size_t tail = size % 512;
+
+ return tail ? istream_skip(fp, 512 - tail) : 0;
+}
+
+int skip_entry(istream_t *fp, sqfs_u64 size)
+{
+ size_t tail = size % 512;
+
+ return istream_skip(fp, tail ? (size + 512 - tail) : size);
+}
diff --git a/lib/tar/read_retry.c b/lib/tar/read_retry.c
deleted file mode 100644
index 2a2f82c..0000000
--- a/lib/tar/read_retry.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * read_retry.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "tar.h"
-#include "internal.h"
-
-int read_retry(const char *errstr, FILE *fp, void *buffer, size_t size)
-{
- size_t ret;
-
- while (size > 0) {
- if (ferror(fp)) {
- fprintf(stderr, "%s: error reading from file\n",
- errstr);
- return -1;
- }
-
- if (feof(fp)) {
- fprintf(stderr, "%s: short read\n", errstr);
- return -1;
- }
-
- ret = fread(buffer, 1, size, fp);
- size -= ret;
- buffer = (char *)buffer + ret;
- }
-
- return 0;
-}
-
-char *record_to_memory(FILE *fp, sqfs_u64 size)
-{
- char *buffer = malloc(size + 1);
-
- if (buffer == NULL)
- goto fail_errno;
-
- if (read_retry("reading tar record", fp, buffer, size))
- goto fail;
-
- if (skip_padding(fp, size))
- goto fail;
-
- buffer[size] = '\0';
- return buffer;
-fail_errno:
- perror("reading tar record");
- goto fail;
-fail:
- free(buffer);
- return NULL;
-}
diff --git a/lib/tar/read_sparse_map_new.c b/lib/tar/read_sparse_map_new.c
index f4f0f92..d9f6c6e 100644
--- a/lib/tar/read_sparse_map_new.c
+++ b/lib/tar/read_sparse_map_new.c
@@ -28,7 +28,7 @@ static int decode(const char *str, size_t len, size_t *out)
return (*str == '\n') ? ((int)count + 1) : -1;
}
-sparse_map_t *read_gnu_new_sparse(FILE *fp, tar_header_decoded_t *out)
+sparse_map_t *read_gnu_new_sparse(istream_t *fp, tar_header_decoded_t *out)
{
sparse_map_t *last = NULL, *list = NULL, *ent = NULL;
size_t i, count, value;
@@ -38,8 +38,12 @@ sparse_map_t *read_gnu_new_sparse(FILE *fp, tar_header_decoded_t *out)
if (out->record_size < 512)
goto fail_format;
- if (read_retry("reading GNU sparse map", fp, buffer, 512))
- return NULL;
+ ret = istream_read(fp, buffer, 512);
+ if (ret < 0)
+ goto fail;
+
+ if (ret < 512)
+ goto fail_format;
diff = decode(buffer, 512, &count);
if (diff <= 0)
@@ -61,10 +65,12 @@ sparse_map_t *read_gnu_new_sparse(FILE *fp, tar_header_decoded_t *out)
if (out->record_size < 512)
goto fail_format;
- if (read_retry("reading GNU sparse map", fp,
- buffer + 512, 512)) {
- return NULL;
- }
+ ret = istream_read(fp, buffer + 512, 512);
+ if (ret < 0)
+ goto fail;
+
+ if (ret < 512)
+ goto fail_format;
ret = decode(buffer + diff, 1024 - diff, &value);
if (ret <= 0)
diff --git a/lib/tar/read_sparse_map_old.c b/lib/tar/read_sparse_map_old.c
index 84e1f9e..cd7177d 100644
--- a/lib/tar/read_sparse_map_old.c
+++ b/lib/tar/read_sparse_map_old.c
@@ -8,12 +8,12 @@
#include "internal.h"
-sparse_map_t *read_gnu_old_sparse(FILE *fp, tar_header_t *hdr)
+sparse_map_t *read_gnu_old_sparse(istream_t *fp, tar_header_t *hdr)
{
sparse_map_t *list = NULL, *end = NULL, *node;
gnu_sparse_t sph;
sqfs_u64 off, sz;
- int i;
+ int i, ret;
for (i = 0; i < 4; ++i) {
if (!isdigit(hdr->tail.gnu.sparse[i].offset[0]))
@@ -47,8 +47,14 @@ sparse_map_t *read_gnu_old_sparse(FILE *fp, tar_header_t *hdr)
return list;
do {
- if (read_retry("reading GNU sparse header",
- fp, &sph, sizeof(sph))) {
+ ret = istream_read(fp, &sph, sizeof(sph));
+ if (ret < 0)
+ goto fail;
+
+ if ((size_t)ret < sizeof(sph)) {
+ fputs("reading GNU sparse header: "
+ "unexpected end-of-file\n",
+ stderr);
goto fail;
}
diff --git a/lib/tar/record_to_memory.c b/lib/tar/record_to_memory.c
new file mode 100644
index 0000000..822608c
--- /dev/null
+++ b/lib/tar/record_to_memory.c
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * record_to_memory.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "tar.h"
+#include "internal.h"
+
+char *record_to_memory(istream_t *fp, size_t size)
+{
+ char *buffer = malloc(size + 1);
+ int ret;
+
+ if (buffer == NULL)
+ goto fail_errno;
+
+ ret = istream_read(fp, buffer, size);
+ if (ret < 0)
+ goto fail;
+
+ if ((size_t)ret < size) {
+ fputs("Reading tar record: unexpected end-of-file.\n", stderr);
+ goto fail;
+ }
+
+ if (skip_padding(fp, size))
+ goto fail;
+
+ buffer[size] = '\0';
+ return buffer;
+fail_errno:
+ perror("reading tar record");
+ goto fail;
+fail:
+ free(buffer);
+ return NULL;
+}
diff --git a/lib/tar/skip.c b/lib/tar/skip.c
deleted file mode 100644
index 36cd470..0000000
--- a/lib/tar/skip.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * skip.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "tar.h"
-
-#include <stdio.h>
-
-static int skip_bytes(FILE *fp, sqfs_u64 size)
-{
- unsigned char buffer[1024];
- size_t diff;
-
- while (size != 0) {
- diff = sizeof(buffer);
- if (diff > size)
- diff = size;
-
- if (read_retry("reading tar record padding", fp, buffer, diff))
- return -1;
-
- size -= diff;
- }
-
- return 0;
-}
-
-int skip_padding(FILE *fp, sqfs_u64 size)
-{
- size_t tail = size % 512;
-
- return tail ? skip_bytes(fp, 512 - tail) : 0;
-}
-
-int skip_entry(FILE *fp, sqfs_u64 size)
-{
- size_t tail = size % 512;
-
- return skip_bytes(fp, tail ? (size + 512 - tail) : size);
-}
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 809ff07..94bfd4b 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -62,164 +62,164 @@ test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c
test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1
test_tar_gnu0_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_gnu0_LDADD = libtar.a libcompat.a
+test_tar_gnu0_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu0_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar
test_tar_gnu1_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_gnu1_LDADD = libtar.a libcompat.a
+test_tar_gnu1_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu1_CPPFLAGS += -DTESTFILE=format-acceptance/gnu-g.tar
test_tar_gnu2_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_gnu2_LDADD = libtar.a libcompat.a
+test_tar_gnu2_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu2_CPPFLAGS += -DTESTFILE=user-group-largenum/gnu.tar
test_tar_gnu2_CPPFLAGS += -DTESTUID=0x80000000 -DTESTGID=0x80000000
test_tar_gnu2_CPPFLAGS += -DTESTTS=1542995392
test_tar_gnu3_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_gnu3_LDADD = libtar.a libcompat.a
+test_tar_gnu3_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu3_CPPFLAGS += -DTESTFILE=negative-mtime/gnu.tar -DTESTTS=-315622800
test_tar_gnu4_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_gnu4_LDADD = libtar.a libcompat.a
+test_tar_gnu4_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu4_CPPFLAGS += -DTESTFILE=long-paths/gnu.tar -DLONG_NAME_TEST
test_tar_gnu4_CPPFLAGS += -DTESTTS=1542909670
test_tar_gnu5_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_gnu5_LDADD = libtar.a libcompat.a
+test_tar_gnu5_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu5_CPPFLAGS += -DTESTFILE=large-mtime/gnu.tar -DTESTTS=8589934592L
test_tar_gnu6_SOURCES = tests/tar_big_file.c tests/test.h tests/test_tar.h
-test_tar_gnu6_LDADD = libtar.a libcompat.a
+test_tar_gnu6_LDADD = libtar.a libfstream.a libcompat.a
test_tar_gnu6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_gnu6_CPPFLAGS += -DTESTFILE=file-size/gnu.tar
test_tar_pax0_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_pax0_LDADD = libtar.a libcompat.a
+test_tar_pax0_LDADD = libtar.a libfstream.a libcompat.a
test_tar_pax0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_pax0_CPPFLAGS += -DTESTFILE=format-acceptance/pax.tar
test_tar_pax1_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_pax1_LDADD = libtar.a libcompat.a
+test_tar_pax1_LDADD = libtar.a libfstream.a libcompat.a
test_tar_pax1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_pax1_CPPFLAGS += -DTESTFILE=user-group-largenum/pax.tar
test_tar_pax1_CPPFLAGS += -DTESTUID=2147483648UL -DTESTGID=2147483648UL
test_tar_pax1_CPPFLAGS += -DTESTTS=1542995392
test_tar_pax2_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_pax2_LDADD = libtar.a libcompat.a
+test_tar_pax2_LDADD = libtar.a libfstream.a libcompat.a
test_tar_pax2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_pax2_CPPFLAGS += -DTESTFILE=large-mtime/pax.tar -DTESTTS=8589934592L
test_tar_pax3_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_pax3_LDADD = libtar.a libcompat.a
+test_tar_pax3_LDADD = libtar.a libfstream.a libcompat.a
test_tar_pax3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_pax3_CPPFLAGS += -DTESTFILE=negative-mtime/pax.tar -DTESTTS=-315622800
test_tar_pax4_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_pax4_LDADD = libtar.a libcompat.a
+test_tar_pax4_LDADD = libtar.a libfstream.a libcompat.a
test_tar_pax4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_pax4_CPPFLAGS += -DTESTFILE=long-paths/pax.tar
test_tar_pax4_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670
test_tar_pax5_SOURCES = tests/tar_big_file.c tests/test.h tests/test_tar.h
-test_tar_pax5_LDADD = libtar.a libcompat.a
+test_tar_pax5_LDADD = libtar.a libfstream.a libcompat.a
test_tar_pax5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_pax5_CPPFLAGS += -DTESTFILE=file-size/pax.tar
test_tar_ustar0_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_ustar0_LDADD = libtar.a libcompat.a
+test_tar_ustar0_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar0_CPPFLAGS += -DTESTFILE=format-acceptance/ustar.tar
test_tar_ustar1_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_ustar1_LDADD = libtar.a libcompat.a
+test_tar_ustar1_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar1_CPPFLAGS += -DTESTFILE=format-acceptance/ustar-pre-posix.tar
test_tar_ustar2_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_ustar2_LDADD = libtar.a libcompat.a
+test_tar_ustar2_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar2_CPPFLAGS += -DTESTFILE=format-acceptance/v7.tar
test_tar_ustar3_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_ustar3_LDADD = libtar.a libcompat.a
+test_tar_ustar3_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar3_CPPFLAGS += -DTESTFILE=user-group-largenum/8-digit.tar
test_tar_ustar3_CPPFLAGS += -DTESTUID=8388608 -DTESTGID=8388608
test_tar_ustar3_CPPFLAGS += -DTESTTS=1542995392
test_tar_ustar4_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_ustar4_LDADD = libtar.a libcompat.a
+test_tar_ustar4_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar4_CPPFLAGS += -DTESTFILE=large-mtime/12-digit.tar
test_tar_ustar4_CPPFLAGS += -DTESTTS=8589934592L
test_tar_ustar5_SOURCES = tests/tar_simple.c tests/test.h tests/test_tar.h
-test_tar_ustar5_LDADD = libtar.a libcompat.a
+test_tar_ustar5_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar5_CPPFLAGS += -DTESTFILE=long-paths/ustar.tar
test_tar_ustar5_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670
test_tar_ustar6_SOURCES = tests/tar_big_file.c tests/test.h tests/test_tar.h
-test_tar_ustar6_LDADD = libtar.a libcompat.a
+test_tar_ustar6_LDADD = libtar.a libfstream.a libcompat.a
test_tar_ustar6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_ustar6_CPPFLAGS += -DTESTFILE=file-size/12-digit.tar
test_tar_target_filled_SOURCES = tests/tar_target_filled.c tests/test.h
test_tar_target_filled_SOURCES += tests/test_tar.h
-test_tar_target_filled_LDADD = libtar.a libcompat.a
+test_tar_target_filled_LDADD = libtar.a libfstream.a libcompat.a
test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_target_filled_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c tests/test.h
test_tar_sparse_gnu_SOURCES += tests/test_tar.h
-test_tar_sparse_gnu_LDADD = libtar.a libcompat.a
+test_tar_sparse_gnu_LDADD = libtar.a libfstream.a libcompat.a
test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu0_SOURCES = tests/tar_sparse.c tests/test.h tests/test_tar.h
-test_tar_sparse_gnu0_LDADD = libtar.a libcompat.a
+test_tar_sparse_gnu0_LDADD = libtar.a libfstream.a libcompat.a
test_tar_sparse_gnu0_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_sparse_gnu0_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu0_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-0.tar
test_tar_sparse_gnu1_SOURCES = tests/tar_sparse.c tests/test.h tests/test_tar.h
-test_tar_sparse_gnu1_LDADD = libtar.a libcompat.a
+test_tar_sparse_gnu1_LDADD = libtar.a libfstream.a libcompat.a
test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_sparse_gnu1_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu1_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-1.tar
test_tar_sparse_gnu2_SOURCES = tests/tar_sparse.c tests/test.h tests/test_tar.h
-test_tar_sparse_gnu2_LDADD = libtar.a libcompat.a
+test_tar_sparse_gnu2_LDADD = libtar.a libfstream.a libcompat.a
test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_sparse_gnu2_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu2_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu1-0.tar
test_tar_sparse_gnu3_SOURCES = tests/tar_sparse.c tests/test.h tests/test_tar.h
-test_tar_sparse_gnu3_LDADD = libtar.a libcompat.a
+test_tar_sparse_gnu3_LDADD = libtar.a libfstream.a libcompat.a
test_tar_sparse_gnu3_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_sparse_gnu3_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu3_CPPFLAGS += -DTESTFILE=sparse-files/gnu.tar
test_tar_xattr_bsd_SOURCES = tests/tar_xattr.c tests/test.h tests/test_tar.h
-test_tar_xattr_bsd_LDADD = libtar.a libcompat.a
+test_tar_xattr_bsd_LDADD = libtar.a libfstream.a libcompat.a
test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_xattr_bsd_CPPFLAGS += -DTESTFILE=xattr/xattr-libarchive.tar
test_tar_xattr_schily_SOURCES = tests/tar_xattr.c tests/test.h tests/test_tar.h
-test_tar_xattr_schily_LDADD = libtar.a libcompat.a
+test_tar_xattr_schily_LDADD = libtar.a libfstream.a libcompat.a
test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_xattr_schily_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_xattr_schily_CPPFLAGS += -DTESTFILE=xattr/xattr-schily.tar
test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_bin.c tests/test.h
test_tar_xattr_schily_bin_SOURCES += tests/test_tar.h
-test_tar_xattr_schily_bin_LDADD = libtar.a libcompat.a
+test_tar_xattr_schily_bin_LDADD = libtar.a libfstream.a libcompat.a
test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_xattr_schily_bin_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_xattr_schily_bin_CPPFLAGS += -DTESTFILE=xattr/xattr-schily-binary.tar
@@ -228,7 +228,7 @@ fstree_fuzz_SOURCES = tests/fstree_fuzz.c
fstree_fuzz_LDADD = libfstree.a libcompat.a
tar_fuzz_SOURCES = tests/tar_fuzz.c
-tar_fuzz_LDADD = libtar.a libcompat.a
+tar_fuzz_LDADD = libtar.a libfstream.a libcompat.a
check_PROGRAMS += test_mknode_simple test_mknode_slink test_mknode_reg
check_PROGRAMS += test_mknode_dir test_gen_inode_numbers test_add_by_path
diff --git a/tests/tar_big_file.c b/tests/tar_big_file.c
index b949f60..66e4690 100644
--- a/tests/tar_big_file.c
+++ b/tests/tar_big_file.c
@@ -9,9 +9,10 @@
int main(void)
{
tar_header_decoded_t hdr;
- FILE *fp;
+ istream_t *fp;
- fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
@@ -22,6 +23,6 @@ int main(void)
TEST_STR_EQUAL(hdr.name, "big-file.bin");
TEST_ASSERT(!hdr.unknown_record);
clear_header(&hdr);
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_fuzz.c b/tests/tar_fuzz.c
index f342e38..e5f5c0b 100644
--- a/tests/tar_fuzz.c
+++ b/tests/tar_fuzz.c
@@ -14,7 +14,7 @@
int main(int argc, char **argv)
{
tar_header_decoded_t hdr;
- FILE *fp;
+ istream_t *fp;
int ret;
if (argc != 2) {
@@ -22,11 +22,9 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- fp = fopen(argv[1], "rb");
- if (fp == NULL) {
- perror(argv[1]);
+ fp = istream_open_file(argv[1]);
+ if (fp == NULL)
return EXIT_FAILURE;
- }
for (;;) {
ret = read_header(fp, &hdr);
@@ -35,16 +33,16 @@ int main(int argc, char **argv)
if (ret < 0)
goto fail;
- ret = fseek(fp, hdr.sb.st_size, SEEK_CUR);
+ ret = istream_skip(fp, hdr.sb.st_size);
clear_header(&hdr);
if (ret < 0)
goto fail;
}
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
fail:
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_FAILURE;
}
diff --git a/tests/tar_simple.c b/tests/tar_simple.c
index 02bd521..6c5a47e 100644
--- a/tests/tar_simple.c
+++ b/tests/tar_simple.c
@@ -36,9 +36,10 @@ int main(void)
tar_header_decoded_t hdr;
char buffer[6];
sqfs_s64 ts;
- FILE *fp;
+ istream_t *fp;
- fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
TEST_EQUAL_UI(hdr.sb.st_uid, TESTUID);
@@ -57,10 +58,10 @@ int main(void)
TEST_STR_EQUAL(hdr.name, fname);
TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("tar data", fp, buffer, 5) == 0);
+ TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
clear_header(&hdr);
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse.c b/tests/tar_sparse.c
index 50940d0..8e2976f 100644
--- a/tests/tar_sparse.c
+++ b/tests/tar_sparse.c
@@ -10,9 +10,10 @@ static void test_case_sparse(const char *path)
{
tar_header_decoded_t hdr;
sparse_map_t *sparse;
- FILE *fp;
+ istream_t *fp;
- fp = test_open_read(path);
+ fp = istream_open_file(path);
+ TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
@@ -72,7 +73,7 @@ static void test_case_sparse(const char *path)
TEST_NULL(sparse);
clear_header(&hdr);
- fclose(fp);
+ sqfs_destroy(fp);
}
int main(void)
diff --git a/tests/tar_sparse_gnu.c b/tests/tar_sparse_gnu.c
index 216a54a..c1854a1 100644
--- a/tests/tar_sparse_gnu.c
+++ b/tests/tar_sparse_gnu.c
@@ -10,11 +10,12 @@ int main(void)
{
tar_header_decoded_t hdr;
sparse_map_t *sparse;
- FILE *fp;
+ istream_t *fp;
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("sparse-files/gnu-small.tar");
+ fp = istream_open_file("sparse-files/gnu-small.tar");
+ TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
@@ -43,6 +44,6 @@ int main(void)
TEST_NULL(sparse->next);
clear_header(&hdr);
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_target_filled.c b/tests/tar_target_filled.c
index 4098b39..7032239 100644
--- a/tests/tar_target_filled.c
+++ b/tests/tar_target_filled.c
@@ -10,11 +10,12 @@ int main(void)
{
tar_header_decoded_t hdr;
char buffer[16];
- FILE *fp;
+ istream_t *fp;
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("format-acceptance/link_filled.tar");
+ fp = istream_open_file("format-acceptance/link_filled.tar");
+ TEST_NOT_NULL(fp);
/* "deep" directory hierarchy containg 2 files */
TEST_ASSERT(read_header(fp, &hdr) == 0);
@@ -45,7 +46,7 @@ int main(void)
"20_characters_here03/20_characters_here04/"
"errored_file_tst");
TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
+ TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
TEST_ASSERT(skip_padding(fp, 5) == 0);
@@ -57,7 +58,7 @@ int main(void)
"20_characters_here03/20_characters_here04/"
"some_test_file");
TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0);
+ TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
TEST_ASSERT(skip_padding(fp, 5) == 0);
@@ -99,7 +100,7 @@ int main(void)
/* end of file */
TEST_ASSERT(read_header(fp, &hdr) > 0);
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr.c b/tests/tar_xattr.c
index 179af2e..e06b428 100644
--- a/tests/tar_xattr.c
+++ b/tests/tar_xattr.c
@@ -10,9 +10,10 @@ int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- FILE *fp;
+ istream_t *fp;
- fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
@@ -22,7 +23,7 @@ int main(void)
TEST_EQUAL_UI(hdr.mtime, 1543094477);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("reading tar data", fp, buffer, 5) == 0);
+ TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
@@ -33,6 +34,6 @@ int main(void)
TEST_NULL(hdr.xattr->next);
clear_header(&hdr);
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr_bin.c b/tests/tar_xattr_bin.c
index ca0f918..88bf3fd 100644
--- a/tests/tar_xattr_bin.c
+++ b/tests/tar_xattr_bin.c
@@ -18,9 +18,10 @@ int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- FILE *fp;
+ istream_t *fp;
- fp = test_open_read(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
+ TEST_NOT_NULL(fp);
TEST_ASSERT(read_header(fp, &hdr) == 0);
TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
@@ -30,7 +31,7 @@ int main(void)
TEST_EQUAL_UI(hdr.mtime, 1543094477);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
+ TEST_ASSERT(istream_read(fp, buffer, 5) == 5);
buffer[5] = '\0';
TEST_STR_EQUAL(buffer, "test\n");
@@ -41,6 +42,6 @@ int main(void)
TEST_NULL(hdr.xattr->next);
clear_header(&hdr);
- fclose(fp);
+ sqfs_destroy(fp);
return EXIT_SUCCESS;
}