You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ownCloud-6.0.0alpha2 and files without file extension #5516
ownCloud-6.0.0alpha1 and ownCloud-6.0.0alpha2 show a defective behavior under the following conditions:
ownCloud is hosted on a Unix system (e.g. Oracle Solaris) which has got a "/usr/bin/file" command that behaves differently than the GNU file command (i.e. as no possibility to analyze the MIME type)
and a file without an file extension containing random binary data is uploaded.
If both conditions occur, I get the following error message from ownCloud:
An exception occurred while executing 'INSERT INTO "oc_mimetypes"("mimetype") VALUES(?)': SQLSTATE[23000]: Integrity constraint violation: 19 column mimetype is not unique
The folder which contains the file isn't accessible anymore.
The problem is most probably caused in the function detect() in "/lib/private/files/type/detection.php". There the following command is called:
Solaris' /usr/bin/file command doesn't understand these command line options. As far as I know, it doesn't even offer the possibility to report a file's mime type.
Steps to reproduce:
Install ownCloud-6.0.0beta1 on a Oracle Solaris 11.1 host.
Upload a testfile via web frontend to owncloud which contains, for example, 128 MB of random data (created, for example, with the following command: dd if=/dev/urandom of=/dev/Testfile_128_MB bs=1024 count=131072). It is important that the file has no file extension (e.g. "bin").
Note:
The problem does not occur with ownCloud-5.0.12 on the same Solaris 11.1 server. The problem does not occur when the file's name is changed to a name with an extension. The problem does not occur when a file is uploaded which contains plain ASCII text and has no file extension, either.
The duplicate problem is indeed fixed in beta1, so I don't get the SQL Exception anymore.
Nevertheless, the misbehaving Solaris file utility is a problem as it overwrites the mime type with an empty string. PHP fileinfo is included in PHP-5.4.20 as it has been compiled with "--enable-fileinfo" (and a "php -m" also confirms that it is there).
Let's have a look at detection.php:
publicfunctiondetect($path) {
$isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://');
if (@is_dir($path)) {
// directories are easyreturn"httpd/unix-directory";
}
$mimeType = $this->detectPath($path);
if ($mimeType === 'application/octet-stream'andfunction_exists('finfo_open')
andfunction_exists('finfo_file') and$finfo = finfo_open(FILEINFO_MIME)
) {
$info = @strtolower(finfo_file($finfo, $path));
if ($info) {
$mimeType = substr($info, 0, strpos($info, ';'));
\OC_Log::write('core', "finfo: " . $mimeType, \OC_Log::INFO);
}
finfo_close($finfo);
}
if (!$isWrappedand$mimeType === 'application/octet-stream' && function_exists("mime_content_type")) {
// use mime magic extension if available$mimeType = mime_content_type($path);
\OC_Log::write('core', "mimeType: " . $mimeType, \OC_Log::INFO);
}
if (!$isWrappedand$mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) {
// it looks like we have a 'file' command,// lets see if it does have mime support$path = escapeshellarg($path);
$fp = popen("file -b --mime-type $path 2>/dev/null", "r");
$reply = fgets($fp);
pclose($fp);
//trim the newline$mimeType = trim($reply);
\OC_Log::write('core', "file: " . $mimeType, \OC_Log::INFO);
}
return$mimeType;
}
As you can see, I've added three OC_Log outputs. When uploading a binary file without an extension, I get the following outputs in the log (with alpha1, alpha2 as well as with beta1):
So the mime type "application/octet-stream" is given back by finfo_file() and by mime_content_type(). But in the last if clause, it gets overwritten with the empty string as Solaris' file utility doesn't behave as expected by ownCloud. When doing a "file -b --mime-type $path 2>/dev/null" in Solaris, I always get the empty string as a result because "file -b --mime-type $path" only produces an error:
As a result, ownCloud works with the empty string for the mime type.
In alpha1 and alpha2 this leads to the SQL Exception which I mentioned. In beta1 this doesn't result in the SQL Exception anymore, but the mime type of a binary file without an extension will stay the empty string (instead of "application/octet-stream"). This doesn't seem to affect ownCloud at all, but in my opinion it is quite inelegant to see that "application/octet-stream" is actually overwritten by "". I'd prefer that the sanity of the file utility is checked before being executed. At least, it should not overwrite an existing mime type by "".
[...] in my opinion it is quite inelegant to see that "application/octet-stream" is actually overwritten by "". I'd prefer that the sanity of the file utility is checked before being executed. At least, it should not overwrite an existing mime type by "".
and
I'd suggest to return the mimetype detected by finfo_file
@steffen-moser Just out of curiousity, what is your database system? According to #5474 an attempt to insert an empty string as a mimetype should fail.
Activity
VicDeo commentedon Oct 24, 2013
@steffen-moser Speaking frankly
fileutility is only a hackish fallback in case fileinfo PHP extension is missing.It is highly recommended to have this extension enabled http://www.php.net/manual/en/book.fileinfo.php
VicDeo commentedon Oct 24, 2013
Might be already fixed in beta1 with 3d5e229
steffen-moser commentedon Oct 29, 2013
The duplicate problem is indeed fixed in beta1, so I don't get the SQL Exception anymore.
Nevertheless, the misbehaving Solaris file utility is a problem as it overwrites the mime type with an empty string. PHP fileinfo is included in PHP-5.4.20 as it has been compiled with "--enable-fileinfo" (and a "php -m" also confirms that it is there).
Let's have a look at detection.php:
As you can see, I've added three OC_Log outputs. When uploading a binary file without an extension, I get the following outputs in the log (with alpha1, alpha2 as well as with beta1):
So the mime type "application/octet-stream" is given back by finfo_file() and by mime_content_type(). But in the last if clause, it gets overwritten with the empty string as Solaris' file utility doesn't behave as expected by ownCloud. When doing a "file -b --mime-type $path 2>/dev/null" in Solaris, I always get the empty string as a result because "file -b --mime-type $path" only produces an error:
As a result, ownCloud works with the empty string for the mime type.
In alpha1 and alpha2 this leads to the SQL Exception which I mentioned. In beta1 this doesn't result in the SQL Exception anymore, but the mime type of a binary file without an extension will stay the empty string (instead of "application/octet-stream"). This doesn't seem to affect ownCloud at all, but in my opinion it is quite inelegant to see that "application/octet-stream" is actually overwritten by "". I'd prefer that the sanity of the file utility is checked before being executed. At least, it should not overwrite an existing mime type by "".
DeepDiver1975 commentedon Oct 29, 2013
I'd suggest to return the mimetype detected by finfo_file.
Executing the file tool should be a fallback only.
@icewind1991 @bantu suggestions?
bantu commentedon Oct 29, 2013
@DeepDiver1975 I agree with
and
DeepDiver1975 commentedon Oct 29, 2013
@bantu can I ask you to submit a pull request for this? Thanks a lot!
This will have a major performance improvement as well from my understanding as described in #5084
@karlitschek FYI
bantu commentedon Oct 29, 2013
@DeepDiver1975 Mimetype detection should probably just use http://api.symfony.com/2.3/Symfony/Component/HttpFoundation/File/MimeType.html. Not sure whether that would be an option for oC6 still.
DeepDiver1975 commentedon Oct 29, 2013
@bantu this might be a valid solution of oc7 - not for oc6 - let's just add that single line of code which returns the mime type 😉 THX
bantu commentedon Oct 29, 2013
@steffen-moser Just out of curiousity, what is your database system? According to #5474 an attempt to insert an empty string as a mimetype should fail.
DeepDiver1975 commentedon Oct 29, 2013
afaik only on Oracle due to different handling of null and empty string
bantu commentedon Oct 29, 2013
Argh. Yes, I forgot to add "... on Oracle".