update attach.filetype field length to match photo.mimetype field length and attempt to find mimetype with finfo class if applicable.

This commit is contained in:
Mario Vavti
2026-01-05 15:34:42 +01:00
parent 933b4fbcfe
commit 9019636449
5 changed files with 47 additions and 9 deletions

30
Zotlabs/Update/_1265.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
namespace Zotlabs\Update;
class _1265 {
function run() {
dbq("START TRANSACTION");
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
$r = dbq("ALTER TABLE attach ALTER COLUMN filetype TYPE VARCHAR(128), ALTER COLUMN filetype SET NOT NULL, ALTER COLUMN filetype SET DEFAULT ''");
}
if(ACTIVE_DBTYPE == DBTYPE_MYSQL) {
$r = dbq("ALTER TABLE attach CHANGE filetype filetype CHAR(128) NOT NULL DEFAULT ''");
}
if($r) {
dbq("COMMIT");
return UPDATE_SUCCESS;
}
q("ROLLBACK");
return UPDATE_FAILED;
}
}

View File

@@ -73,7 +73,7 @@ define('PLATFORM_NAME', 'hubzilla');
define('STD_VERSION', '10.7.14');
define('ZOT_REVISION', '6.0');
define('DB_UPDATE_VERSION', 1264);
define('DB_UPDATE_VERSION', 1265);
define('PROJECT_BASE', __DIR__);

View File

@@ -101,14 +101,10 @@ function z_mime_content_type($filename) {
// ms office
'doc' => 'application/msword',
// FIXME: this is the correct mime type for docx but it is too long to store in DB (postrges) as of 2026-01-05
// 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'docx' => 'application/vnd.ms-word',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
// FIXME: this is the correct mime type for xlsx but it is too long to store in DB (postrges) as of 2026-01-05
//'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlsx' => 'application/vnd.ms-excel',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'ppt' => 'application/vnd.ms-powerpoint',
// open office
@@ -894,6 +890,18 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
else
$edited = $created;
// Until here we either used the provided mime type or set mimetype by extension.
// Both variants are inherently unsafe hence try to find and set the real mimetype before storage.
if (class_exists('finfo') && is_file($os_basepath . $os_relpath)) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimetype = $finfo->file($os_basepath . $os_relpath);
if ($mimetype === false) {
$mimetype = 'application/octet-stream';
}
}
if($options === 'replace') {
$r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, content = '%s', edited = '%s', os_path = '%s', display_path = '%s' where id = %d and uid = %d",
dbesc($filename),

View File

@@ -171,7 +171,7 @@ CREATE TABLE IF NOT EXISTS `attach` (
`hash` char(191) NOT NULL DEFAULT '',
`creator` char(191) NOT NULL DEFAULT '',
`filename` char(191) NOT NULL DEFAULT '',
`filetype` char(191) NOT NULL DEFAULT '',
`filetype` char(128) NOT NULL DEFAULT '',
`filesize` int(10) unsigned NOT NULL DEFAULT 0 ,
`revision` int(10) unsigned NOT NULL DEFAULT 0 ,
`folder` char(191) NOT NULL DEFAULT '',

View File

@@ -168,7 +168,7 @@ CREATE TABLE "attach" (
"hash" varchar(64) NOT NULL DEFAULT '',
"creator" varchar(128) NOT NULL DEFAULT '',
"filename" text NOT NULL DEFAULT '',
"filetype" varchar(64) NOT NULL DEFAULT '',
"filetype" varchar(128) NOT NULL DEFAULT '',
"filesize" bigint NOT NULL DEFAULT '0',
"revision" bigint NOT NULL DEFAULT '0',
"folder" varchar(64) NOT NULL DEFAULT '',