View Issue Details

IDProjectCategoryView StatusLast Update
0000656fileGeneralpublic2025-05-10 12:57
Reporterharry.sintonen Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
Product Version5.46 
Summary0000656: byteswap mistake prevents loading cross-endian generated magic files
Descriptionsrc/apprentice.c "bs1" function does:

 bs1(struct magic *m)
 {
       m->cont_level = swap2(m->cont_level);
...

However, "cont_level" is uint8_t and thus must not be swapped. What _should_ be swapped instead is "flag" that is uint16_t. Removing the bogus "cont_level" byteswap and adding one for "flag" fixes file. See the attached patch.

This was broken in commit https://github.com/file/file/commit/0f3bf841b87cbca423af53a5a7adce3fbf88b71a which changed the "flag" and "cont_level" bytes without fixing the "bs1" function.
Steps To Reproduce1. Cross-compile file on different endian system.
2. When using file is unable to load the magic file generated during the cross-compile process.
Additional Information--- file-5.46/src/apprentice.c.orig 2024-11-27 17:37:00.000000000 +0200
+++ file-5.46/src/apprentice.c 2025-05-10 15:19:16.866699397 +0300
@@ -3644,7 +3644,7 @@
 file_private void
 bs1(struct magic *m)
 {
- m->cont_level = swap2(m->cont_level);
+ m->flag = swap2(m->flag);
     m->offset = swap4(CAST(uint32_t, m->offset));
     m->in_offset = swap4(CAST(uint32_t, m->in_offset));
     m->lineno = swap4(CAST(uint32_t, m->lineno));
TagsNo tags attached.

Activities

harry.sintonen

2025-05-10 12:55

reporter  

file-5.46-endian-fix.diff (423 bytes)   
--- file-5.46/src/apprentice.c.orig	2024-11-27 17:37:00.000000000 +0200
+++ file-5.46/src/apprentice.c	2025-05-10 15:19:16.866699397 +0300
@@ -3644,7 +3644,7 @@
 file_private void
 bs1(struct magic *m)
 {
-	m->cont_level = swap2(m->cont_level);
+	m->flag = swap2(m->flag);
 	m->offset = swap4(CAST(uint32_t, m->offset));
 	m->in_offset = swap4(CAST(uint32_t, m->in_offset));
 	m->lineno = swap4(CAST(uint32_t, m->lineno));
file-5.46-endian-fix.diff (423 bytes)   

harry.sintonen

2025-05-10 12:57

reporter   ~0004224

Oops a typo: s/bytes/types/g

Issue History

Date Modified Username Field Change
2025-05-10 12:55 harry.sintonen New Issue
2025-05-10 12:55 harry.sintonen File Added: file-5.46-endian-fix.diff
2025-05-10 12:57 harry.sintonen Note Added: 0004224