diff --git a/Zotlabs/Update/_1265.php b/Zotlabs/Update/_1265.php new file mode 100644 index 000000000..96a6784da --- /dev/null +++ b/Zotlabs/Update/_1265.php @@ -0,0 +1,30 @@ + '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), diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql index 3d8db255f..dcc41491d 100644 --- a/install/schema_mysql.sql +++ b/install/schema_mysql.sql @@ -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 '', diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql index 789167938..230e12e33 100644 --- a/install/schema_postgres.sql +++ b/install/schema_postgres.sql @@ -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 '',