[Bug]: Detection::detectString() / detectContent() never use finfo – missing use finfo; (regression from #54077)

Aperta Adatta ai principianti
#66,239 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Inizia da lib/private/Files/Type/Detection.php, dove detectContent() e detectString() fanno riferimento a finfo::class e new finfo(...) senza un import use finfo;, quindi la ricerca si risolve in OC\Files\Type\finfo. Aggiungi l'import globale mancante e verifica che il ramo finfo venga eseguito quando ext-fileinfo è caricata. È completato quando detectString() restituisce image/vnd.microsoft.icon invece di application/octet-stream per i byte del favicon.ico di heise.de.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

0. Needs triage 35-feedback bug
⚠️ This issue respects the following points: ⚠️
  • This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug (if unsure, ask the Community Help Forum).
  • This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
  • I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (Supported major versions and current patch levels).
  • I agree to follow Nextcloud's Code of Conduct.
  • I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description

Since #54077 (refactor(IMimeTypeDetector): streamline finfo usage + misc tidying), lib/private/Files/Type/Detection.php uses class_exists(finfo::class) and new finfo(...). The file is in namespace OC\Files\Type, but there is no use finfo; import. finfo::class therefore resolves to OC\Files\Type\finfo, class_exists() is always false, and the finfo branch never runs, even when ext-fileinfo is loaded.

Affected: detectString() (line ~302) and detectContent() (line ~228). Present in v35.0.2, stable34, stable35 and master.

Effect: detectString() falls back to writing a temp file and calling detect() → detectContent() → mime_content_type(). That result goes through getSecureMimeType(), which maps MIME types that are not in the mimetype list (e.g. image/vnd.microsoft.icon) to application/octet-stream. Before the refactor, finfo_buffer() returned the real type.

Visible consequence: In the Mail app, favicon avatars no longer show up. FaviconSource calls IMimeTypeDetector::detectString(), gets application/octet-stream for .ico favicons, and AvatarService::hasAllowedMime() rejects the result. I suspect this is also why FaviconSourceTest::testFetchNoCacheFiles was dropped as "flaky" in nextcloud/mail#12578.

Steps to reproduce
<?php
require 'lib/base.php';
$d = \OCP\Server::get(\OCP\Files\IMimeTypeDetector::class);
$ico = file_get_contents('https://heise.de/favicon.ico');
var_dump(class_exists('OC\Files\Type\finfo'));                // false
var_dump($d->detectString($ico));                             // "application/octet-stream"
var_dump((new \finfo(FILEINFO_MIME_TYPE))->buffer($ico));     // "image/vnd.microsoft.icon"
Expected behavior

detectString() returns image/vnd.microsoft.icon, as it did before #54077.

Nextcloud Server version

35

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.4

Web server

Nginx

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report

List of activated Apps

Nextcloud Signing status

Nextcloud Logs

Additional info

No response

Lingua principale
PHP
Stelle
37.3k
Fork
5.3k
Merge medio
2g 14h
PR unite (30g)
636

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nextcloud/server

Tutte le issue di nextcloud/server

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.