ArturSierzant / OMPD

O!MPD is free, opensource MPD client based on PHP and mySQL.
http://ompd.pl
GNU General Public License v3.0
40 stars 13 forks source link

Unable to add track with file name containing unicode flags #168

Open tomchiverton opened 3 months ago

tomchiverton commented 3 months ago
Uncaught mysqli_sql_exception: Incorrect string value: '\xF0\x9F\x87\xA6\xF0\x9F...' for column `ompd`.`track`.`relative_file` at row 1 in /home/ompd/update.php:928 Stack trace: #0 /home/ompd/update.php(928): mysqli_query(Object(mysqli), 'INSERT INTO tra...') #1 /home/ompd/update.php(587): fileStructure('/exports/mp3/Al...', Array, Array, 'hpkoowgoqf', '1715343516') #2 /home/ompd/update.php(501): recursiveScan('/exports/mp3/Al...') #3 /home/ompd/update.php(501): recursiveScan('/exports/mp3/Al...') #4 /home/ompd/update.php(351): recursiveScan('/exports/mp3/') #5 /home/ompd/update.php(78): update('') #6 {main} thrown 

The file name is Kaleen - We Will Rave (LIVE) | Austria 🇦🇹 Second Semi-Final | Eurovision 2024 [KqSuRaN9zFk].mp3

The database column is text which should support this if I read the MariaDB docs right.

Code appears to use non-paramatised string bashing.

Would you be open to a MR that changed this query as per https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php ?

tomchiverton commented 3 months ago

Turns out that wasn't it, the column needed to be

ALTER TABLE ompd.track MODIFY COLUMN relative_file text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' NOT NULL;

I'm not sure what the default from the installer script is.