View Issue Details

IDProjectCategoryView StatusLast Update
0000616filegeneralpublic2017-05-24 19:20
ReporterKrzysztof Wilczynski 
Assigned ToChristos Zoulas 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.30 
Target VersionFixed in VersionHEAD 
Summary0000616: New flags details expected results and error handling.
DescriptionI added the new flags which were introduced in the libmagic 5.23 to my project. The addition was simple enough, as these are just new flags. But when I got to testing how they work, I've noticed
that the behaviour is quite different to let's say MAGIC_MIME, etc. Especially, when MAGIC_EXTENSION and MAGIC_NODESC are set, the results and error handling is very different.

A few simple test cases to reproduce what I am seeing:

(1 to 3 do not use MAGIC_ERROR; 11 to 13 have MAGIC_ERROR set)

$ gcc test.c -o test -Wall -lmagic
$ for p in / /etc/hosts /1; do for n in 1 2 3 11 12 13; do printf "%02s - " $n; ./test $n $p; done; echo; done
 1 - /: flag = 1040, result = inode/directory; charset=binary, errno = 0, error = (null)
 2 - /: flag = 16777216, result = (null), errno = 21, error = cannot read `/' (Is a directory)
 3 - /: flag = 16780304, result = (null), errno = 21, error = cannot read `/' (Is a directory)
11 - /: flag = 1552, result = inode/directory; charset=binary, errno = 0, error = (null)
12 - /: flag = 16777728, result = (null), errno = 21, error = cannot read `/' (Is a directory)
13 - /: flag = 16780816, result = (null), errno = 21, error = cannot read `/' (Is a directory)

 1 - /etc/hosts: flag = 1040, result = text/plain; charset=us-ascii, errno = 0, error = (null)
 2 - /etc/hosts: flag = 16777216, result = ???, errno = 0, error = (null)
 3 - /etc/hosts: flag = 16780304, result = application/octet-stream; charset=us-ascii, errno = 0, error = (null)
11 - /etc/hosts: flag = 1552, result = text/plain; charset=us-ascii, errno = 0, error = (null)
12 - /etc/hosts: flag = 16777728, result = ???, errno = 0, error = (null)
13 - /etc/hosts: flag = 16780816, result = application/octet-stream; charset=us-ascii, errno = 0, error = (null)

 1 - /1: flag = 1040, result = cannot open `/1' (No such file or directory), errno = 0, error = (null)
 2 - /1: flag = 16777216, result = (null), errno = 0, error = (null)
 3 - /1: flag = 16780304, result = (null), errno = 0, error = (null)
11 - /1: flag = 1552, result = (null), errno = 2, error = cannot stat `/1' (No such file or directory)
12 - /1: flag = 16777728, result = (null), errno = 0, error = (null)
13 - /1: flag = 16780816, result = (null), errno = 0, error = (null)

As per the above, I am not sure what MAGIC_EXTENSION returns as "???", or what should be a default behaviour when no file extensions are known. The error handling is also
something that might not be 100% aligned with the rest. When the file/directory is missing there is no error raised, with or without MAGIC_ERROR set.

Having said all that, I am not sure what MAGIC_NODESC really does?

Also, an interesting discovery - when MAGIC_MIME is set (the 1040 decimal) if MAGIC_ERROR is not set, then errno is never set. I know that as per POSIX compatibility
it all changes depending on whether MAGIC_ERROR is set, but I would think that setting errno all the time would be fine?
TagsNo tags attached.

Relationships

Activities

Krzysztof Wilczynski

Krzysztof Wilczynski

2017-05-15 12:56

reporter  

test.c (698 bytes)
Christos Zoulas

Christos Zoulas

2017-05-24 19:20

manager   ~0001522

1. MAGIC_NODESC is a synthetic flag used only internally to mean that the description field is not used.
2. there is a bug in the code:
        if (flag_arg > 10) {
                flag_arg %= 10;
                flag = MAGIC_ERROR;
+ } else
+ flag = 0;
3. Yes you are right, the filesystem checks should run regardless if we ask for an extension/apple or not (fixed)
4. I will leave ??? for now until we come up with something better.

Issue History

Date Modified Username Field Change
2017-05-15 12:56 Krzysztof Wilczynski New Issue
2017-05-15 12:56 Krzysztof Wilczynski File Added: test.c
2017-05-24 19:18 Christos Zoulas Assigned To => Christos Zoulas
2017-05-24 19:18 Christos Zoulas Status new => assigned
2017-05-24 19:20 Christos Zoulas Status assigned => resolved
2017-05-24 19:20 Christos Zoulas Resolution open => fixed
2017-05-24 19:20 Christos Zoulas Fixed in Version => HEAD
2017-05-24 19:20 Christos Zoulas Note Added: 0001522