From 8f7abb631219b4fb58359250337aabf1e6ac4476 Mon Sep 17 00:00:00 2001
From: "Neal H. Walfield" <neal@gnu.org>
Date: Fri, 28 Aug 2020 14:47:39 +0200
Subject: [PATCH 4/4] Save ms->offset around calls to use.

---
 src/softmagic.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/softmagic.c b/src/softmagic.c
index f3ad21d0..5ecdd0b4 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -992,6 +992,10 @@ moffset(struct magic_set *ms, struct magic *m, const struct buffer *b,
 		o = CAST(int32_t, (ms->offset + 2 * sizeof(uint64_t)));
 		break;
 
+	case FILE_USE:
+		o = ms->offset;
+		break;
+
 	default:
 		o = 0;
 		break;
@@ -1574,6 +1578,7 @@ mget(struct magic_set *ms, struct magic *m, const struct buffer *b,
 	union VALUETYPE *p = &ms->ms_value;
 	struct mlist ml;
 	int got_match;
+	uint32_t saved_offset;
 
 	if (*indir_count >= ms->indir_max) {
 		file_error(ms, 0, "indirect count (%hu) exceeded",
@@ -1885,9 +1890,11 @@ mget(struct magic_set *ms, struct magic *m, const struct buffer *b,
 			*need_separator = 0;
 		if (file_check_mem(ms, 0, 1) == -1)
 			return -1;
+                saved_offset = ms->offset;
 		rv = match(ms, ml.magic, ml.nmagic, b, offset + o,
 		    mode, text, flip, indir_count, name_count,
 		    printed_something, need_separator, returnval, found_match);
+                ms->offset = saved_offset;
 		// If the named continuation is empty, then return
 		// true.  Otherwise, return the body's 'got_match' value.
 		if (ml.nmagic == 1) {
-- 
2.20.1

