https://github.com/file/file

Bug introduced in 5.47

commit 08ab5f644bf9822c64faf5efa4e393b58d7bcd0e
Author: Christos Zoulas <christos@zoulas.com>
Date:   Wed May 28 19:22:22 2025 +0000

    PR/622: Odd_Bloke: Handle negative offsets in file_buffer(), when fd is not
    available.

Backport two bug fixes from master.

commit b75b4ac5861ee2207b8bf186e1967602a08fda40
Author: Christos Zoulas <christos@zoulas.com>
Date:   Sat May 9 22:14:09 2026 +0000

    Add missing check to prevent subtraction underflow.
    (evilrabbit @ tutamail dot com)

commit c54605718190ad8fe9c25cb475f1f32ca7cd54f7
Author: Christos Zoulas <christos@zoulas.com>
Date:   Sun Apr 12 22:15:14 2026 +0000

    PR/725: inliniac: Revert previous and always set offset.

Index: src/softmagic.c
--- src/softmagic.c.orig
+++ src/softmagic.c
@@ -1562,6 +1562,8 @@ msetoffset(struct magic_set *ms, struct magic *m, stru
 			return -1;
 		}
 		if (b->fd == -1) {
+			if (CAST(size_t, m->offset) > b->flen)
+				return -1;
 			ms->eoffset = ms->offset =
 			    CAST(int32_t, b->flen - m->offset);
 		} else {
@@ -1580,8 +1582,7 @@ normal:
 			ms->offset = offset;
 			ms->eoffset = 0;
 		} else {
-			if (b->fd != -1)
-				ms->offset = ms->eoffset + offset;
+			ms->offset = ms->eoffset + offset;
 		}
 	}
 	if ((ms->flags & MAGIC_DEBUG) != 0) {
