]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob
627b2c82764de62be9f2609e686a58665645fffc
[git.ikiwiki.info.git] /
1 When uploading a PNG file on the wiki, through the webinterface or anonymous git, i get:
3     icon.png            prohibited by allowed_attachments (file MIME type is application/octet-stream, not application/vnd.oasis.opendocument.*)
5 `attachment_allowed_attachments` is set to:
7     virusfree() and (mimetype(image/*) or mimetype(text/*) or mimetype(application/x-gzip) or mimetype(application/vnd.oasis.opendocument.*)) and maxsize(2048kb)
9 Maybe a bug in the [[plugins/filecheck]] plugin?
11 This is ikiwiki 3.20130904.1~bpo70+1 on Debian wheezy, with some patches applied, namely:
13  * [[todo/option_to_send_only_the_diff_in_notifyemail]]
14  * [[bugs/syslog_fails_with_non-ASCII_wikinames]]
15  * [[bugs/notifyemail_fails_with_some_openid_providers]]
16  * [[bugs/crashes_in_the_python_proxy_even_if_disabled]]
18 Weird... --[[anarcat]]
20 > Well, the pagespec seems to be matching correctly, given that it thinks the mime type is application/octet-stream.
21 > If File::MimeInfo::Magic is installed, ikiwiki uses it. If not, or if it fails to find any mime type, it falls back to using `file -bi`,
22 > and if that fails, it falls back to a default of application/octet-stream. --[[Joey]]
24 > > File::MimeInfo::Magic is installed:
25 > > 
26 > >     ii  libfile-mimeinfo-perl    0.16-1                 all           Perl module to determine file types
27 > > 
28 > > it turns out there's (still) a problem with the way we use the module. This test code:
29 > > 
30 > >     #!/usr/bin/perl -w
31 > >     my $file='icon.png';
32 > >     use File::MimeInfo::Magic;
33 > >     print "mime::magic: " . File::MimeInfo::Magic::magic($file) . "\n";
34 > >     print "mime::default: " . File::MimeInfo::Magic::default($file) . "\n";
35 > > 
36 > > ...returns:
37 > > 
38 > >     mime::magic: image/png
39 > >     mime::default: application/octet-stream
40 > > 
41 > > `file -ib` returns the right thing (`image/png; charset=binary`).
42 > > 
43 > > So it *should* work: it seems that the `::default` code kicks in even if the `::magic` one actually works.
44 > > 
45 > > I have traced down the problem to this block of code:
46 > > 
47 > >         if (! defined $mimetype || $mimetype !~s /;.*//) {
48 > >                 # Fall back to default value.
49 > >                 $mimetype=File::MimeInfo::Magic::default($file)
50 > > 
51 > > If you take a look deeply, this will fire up the default if there's no semicolon in the mimetype, which is expected for `file` calls, but not for `::magic()` calls. So `::magic()` works, but then the `::default` kicks in anyways.
52 > >
53 > > [[!template  id=gitbranch branch=anarcat/dev/magic-fails author="[[anarcat]]"]]
54 > > 
55 > > I have a stupid [[patch]] in my git repo which just appends a semicolon to the `::magic()` output, but maybe this should be done in another way...
56 > > 
57 > > --[[anarcat]]
59 > > > [[!template  id=gitbranch branch=ready/more-magic author="[[smcv]]" browse=http://git.pseudorandom.co.uk/smcv/ikiwiki.git/commitdiff/ready/more-magic]]
60 > > > If the regex match isn't necessary and it's just about deleting the
61 > > > parameters, I think I'd prefer
62 > > >
63 > > >     if (! defined $mimetype) {
64 > > >         ...
65 > > >     }
66 > > >     $mimetype =~ s/;.*//;
67 > > >
68 > > > as done in my `ready/more-magic` branch.
69 > > >
70 > > > I'm a little hesitant to do that without knowing why Joey implemented it
71 > > > the way it is, but as far as I can tell it's just an oversight.
72 > > >
73 > > > Or, if the result of the s/// is checked for a reason, and it's
74 > > > about catching a result from file(1) that
75 > > > is not, in fact, a MIME type at all (empty string or error message
76 > > > or something), maybe something more like this?
77 > > >
78 > > >     if (! defined $mimetype || $mimetype !~ s{[-\w]+/[-\w]+(?:;.*)?}{})
79 > > >
80 > > > (or whatever the allowed characters in MIME types are). --[[smcv]]
82 > > > > I don't mind either way, but i feel this should be fixed for the next release, as I need to reapply this patch at every upgrade now. -- [[anarcat]]
84 > > > > > This is still a problem in 3.20140831. -- [[anarcat]]
86 > > > > > > I still don't think appending a semicolon is the right answer:
87 > > > > > > at best it's equivalent to what I suggested, and at worst it's
88 > > > > > > disabling a check that does have some reason behind it.
89 > > > > > > I've turned the version I suggested above into a proper branch.
90 > > > > > > Review by someone who can commit to ikiwiki.git would be appreciated.
91 > > > > > > --[[smcv]]