View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000656 | file | General | public | 2025-05-10 12:55 | 2025-05-28 15:55 |
| Reporter | harry.sintonen | Assigned To | christos | ||
| Priority | normal | Severity | major | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | 5.46 | ||||
| Fixed in Version | HEAD | ||||
| Summary | 0000656: byteswap mistake prevents loading cross-endian generated magic files | ||||
| Description | src/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 Reproduce | 1. 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)); | ||||
| Tags | No tags attached. | ||||
|
|
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));
|
|
|
Oops a typo: s/bytes/types/g |
|
|
fixed, thanks! |
| 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 | |
| 2025-05-28 15:54 | christos | Assigned To | => christos |
| 2025-05-28 15:54 | christos | Status | new => assigned |
| 2025-05-28 15:55 | christos | Status | assigned => resolved |
| 2025-05-28 15:55 | christos | Resolution | open => fixed |
| 2025-05-28 15:55 | christos | Fixed in Version | => HEAD |
| 2025-05-28 15:55 | christos | Note Added: 0004237 |