]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/can__39__t_upload_a_simple_png_image:_prohibited_by_allowed__95__attachments___40__file_MIME_type_is_application__47__octet-stream....mdwn
f4bc3402ae222d8b05751a9f5c1d6497c899ab4c
[ikiwiki.git] / doc / bugs / can__39__t_upload_a_simple_png_image:_prohibited_by_allowed__95__attachments___40__file_MIME_type_is_application__47__octet-stream....mdwn
1 When uploading a PNG file on the wiki, through the webinterface or anonymous git, i get:
2
3     icon.png            prohibited by allowed_attachments (file MIME type is application/octet-stream, not application/vnd.oasis.opendocument.*)
4
5 `attachment_allowed_attachments` is set to:
6
7     virusfree() and (mimetype(image/*) or mimetype(text/*) or mimetype(application/x-gzip) or mimetype(application/vnd.oasis.opendocument.*)) and maxsize(2048kb)
8
9 Maybe a bug in the [[plugins/filecheck]] plugin?
10
11 This is ikiwiki 3.20130904.1~bpo70+1 on Debian wheezy, with some patches applied, namely:
12
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]]
17
18 Weird... --[[anarcat]]
19
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]]
23
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]]
58
59 > > > If the regex match isn't necessary and it's just about deleting the
60 > > > parameters, I think I'd prefer something like
61 > > >
62 > > >     if (! defined $mimetype) {
63 > > >         ...
64 > > >     }
65 > > >     $mimetype =~ s/;.*//;
66 > > >
67 > > > but I'd be hesitant to do that without knowing why Joey implemented it
68 > > > the way it is. If it's about catching a result from file(1) that
69 > > > is not, in fact, a MIME type at all (empty string or error message
70 > > > or something), maybe something more like this?
71 > > >
72 > > >     if (! defined $mimetype || $mimetype !~ s{[-\w]+/[-\w]+(?:;.*)?}{})
73 > > >
74 > > > (or whatever the allowed characters in MIME types are). --[[smcv]]
75
76 > > > > 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]]
77
78 > > > > > This is still a problem in 3.20140831. -- [[anarcat]]