View Issue Details

IDProjectCategoryView StatusLast Update
0000358fileGeneralpublic2022-07-04 17:01
Reporterjpalus Assigned Tochristos  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.42 
Fixed in VersionHEAD 
Summary0000358: filenames in output limited to single char when reading files from stdin (5.42 regression)
DescriptionWhen reading files from stdin file 5.42 cuts filename in output to single char (see "c" instead of whole "configure.ac"):
```
$ echo configure.ac|./src/file -m magic/magic.mgc -f -
c: M4 macro processor script, ASCII text
```
Appears to be regression introduced by:
https://github.com/file/file/commit/f448f3e5c37de8c285ac14b032b2bdcea82fc08b

where `inname` is now passed to `file_printable` before printing, however last parameter `wid`, that should be length on `inname` is always `1` for input from stdin.
TagsNo tags attached.

Activities

bero

2022-06-14 12:56

reporter   ~0003764

The problem is that stdin can't be rewound, therefore the check for the longest filename size doesn't work. The code is aware of this, but "fixes" it by hardcoding 1.
The attached patch should fix it correctly.
file-5.42-fix-size-of-lines-read-from-stdin.patch (689 bytes)   
diff -up file-5.42/src/file.c.omv~ file-5.42/src/file.c
--- file-5.42/src/file.c.omv~	2022-06-14 14:41:32.708884703 +0200
+++ file-5.42/src/file.c	2022-06-14 14:40:40.436535597 +0200
@@ -509,7 +509,7 @@ unwrap(struct magic_set *ms, const char
 
 	if (strcmp("-", fn) == 0) {
 		f = stdin;
-		wid = 1;
+		wid = 0;
 	} else {
 		if ((f = fopen(fn, "r")) == NULL) {
 			file_warn("Cannot open `%s'", fn);
@@ -530,7 +530,7 @@ unwrap(struct magic_set *ms, const char
 	while ((len = getline(&line, &llen, f)) > 0) {
 		if (line[len - 1] == '\n')
 			line[len - 1] = '\0';
-		e |= process(ms, line, wid);
+		e |= process(ms, line, (wid > 0) ? wid : file_mbswidth(ms, line));
 	}
 
 	free(line);

christos

2022-07-04 17:01

manager   ~0003776

Fixed, thanks!

Issue History

Date Modified Username Field Change
2022-06-12 21:48 jpalus New Issue
2022-06-14 12:56 bero Note Added: 0003764
2022-06-14 12:56 bero File Added: file-5.42-fix-size-of-lines-read-from-stdin.patch
2022-07-04 17:00 christos Assigned To => christos
2022-07-04 17:00 christos Status new => assigned
2022-07-04 17:01 christos Status assigned => resolved
2022-07-04 17:01 christos Resolution open => fixed
2022-07-04 17:01 christos Fixed in Version => HEAD
2022-07-04 17:01 christos Note Added: 0003776