Moode Forum
[SOLVED] Thumbnail Generator Issue in 9.0.0 - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7)
+--- Thread: [SOLVED] Thumbnail Generator Issue in 9.0.0 (/showthread.php?tid=6506)

Pages: 1 2 3 4


RE: Thumbnail Generator Issue in 9.0.0 - Tim Curtis - 05-28-2024

(05-28-2024, 06:23 PM)ftw64 Wrote: Hi Tim,

It seems that this statement in thumb-gen.php (line 318) does not return:

$id3v2 = new Zend_Media_Id3v2($path, array('hash_only' => false)); // r44a

Code:
                case 'mp3':
                        require_once __DIR__ . '/../inc/Zend/Media/Id3v2.php';

                        try {
workerLog('thumb-gen: getImage(): 4 (path = ' . $path . ')');
                                $id3v2 = new Zend_Media_Id3v2($path, array('hash_only' => false)); // r44a
workerLog('thumb-gen: getImage(): 5');

                                if (isset($id3v2->apic)) {


The log prints:

Code:
20240528 201917 thumb-gen: getImage(): 4 (path = /var/lib/mpd/music/NAS/NFS/2/stevie wonder - (2001) vocals and instrumentals pt2 (lg100)/11 - for once in my life.mp3)

and then the thumbnail generator stops and I do not get debug output 'thumb-gen: getImage(): 5' anymore...

Now investigating Zend_Media_Id3v2 ...

-Frank

Back at the start of the Bookworm port I had to fixup some implode() statements in the id3 and iso14496 Zend classes that failed due to not being PHP8 compliant. 

Here's the commit
https://github.com/moode-player/moode/commit/16d922e543a5bb3d7a41b19c9a178588c13af3a1

It' possible other non-php8-compliant code exists in Zend. Just a thought.


RE: Thumbnail Generator Issue in 9.0.0 - ftw64 - 05-28-2024

(05-28-2024, 06:40 PM)Tim Curtis Wrote:
(05-28-2024, 06:23 PM)ftw64 Wrote: Hi Tim,

It seems that this statement in thumb-gen.php (line 318) does not return:

$id3v2 = new Zend_Media_Id3v2($path, array('hash_only' => false)); // r44a

Code:
                case 'mp3':
                        require_once __DIR__ . '/../inc/Zend/Media/Id3v2.php';

                        try {
workerLog('thumb-gen: getImage(): 4 (path = ' . $path . ')');
                                $id3v2 = new Zend_Media_Id3v2($path, array('hash_only' => false)); // r44a
workerLog('thumb-gen: getImage(): 5');

                                if (isset($id3v2->apic)) {


The log prints:

Code:
20240528 201917 thumb-gen: getImage(): 4 (path = /var/lib/mpd/music/NAS/NFS/2/stevie wonder - (2001) vocals and instrumentals pt2 (lg100)/11 - for once in my life.mp3)

and then the thumbnail generator stops and I do not get debug output 'thumb-gen: getImage(): 5' anymore...

Now investigating Zend_Media_Id3v2 ...

-Frank

Back at the start of the Bookworm port I had to fixup some implode() statements in the id3 and iso14496 Zend classes that failed due to not being PHP8 compliant. 

Here's the commit
https://github.com/moode-player/moode/commit/16d922e543a5bb3d7a41b19c9a178588c13af3a1

It' possible other non-php8-compliant code exists in Zend. Just a thought.

I'm absolutely unsure if what I'm doing is correct (have almost no knowledge of PHP). But when I change the implode code in /var/www/inc/Zend/Media/Id3/LinkFrame.php to the below, the thumbnail generator no longer crashes on the offending MP3 file:

Code:
public function __construct($reader = null, &$options = array())
   {
       parent::__construct($reader, $options);

workerLog('Zend_Media_Id3_LinkFrame: 1');
       if ($this->_reader !== null) {
workerLog('Zend_Media_Id3_LinkFrame: 2');
           $this->_link = implode
               ('', $this->_explodeString8
       ($this->_reader->read($this->_reader->getSize()), 1));
workerLog('Zend_Media_Id3_LinkFrame: 3');
       }
   }



However, now it fails on some FLAC other MP3 file... Perhaps there are other incorrect calls to implode in the Zend Framework...
I'll continue debugging...

-Frank


RE: Thumbnail Generator Issue in 9.0.0 - ftw64 - 05-28-2024

Hi Tim,

The other MP3 file fails in /var/www/util/thumb-gen.php line 168 (file_get_contents):


Code:
workerLog('thumb-gen: 10');

        // Image file path, convert image to string
        if (strlen($imgStr) < 512) {
workerLog('thumb-gen: 11, imgStr = ' .$imgStr);
                //workerLog('thumb-gen: Image file: ' . $imgStr);
                $imgStr = file_get_contents($imgStr);
workerLog('thumb-gen: 12');
        }
        else {
                //workerLog('thumb-gen: Embedded image: ' . $file);
        }


My log shows:


Code:
20240528 211547 thumb-gen: 10
20240528 211547 thumb-gen: 11, imgStr =

The function file_get_contents seems a PHP build-in function?

Might be that getImage (using the Zend Framework) does not crash now, but returns an empty string. Would that cause file_get_contents to crash in PHP?
Update: seems that imgStr contains binary date: 4 bytes of '0x00'.

If I add '$image = false' to /var/www/util/thumb-gen.php near line 322 the thumbnail generator works fine:


Code:
                case 'mp3':
                        require_once __DIR__ . '/../inc/Zend/Media/Id3v2.php';
                        try {
                                $id3v2 = new Zend_Media_Id3v2($path, array('hash_only' => false)); // r44a

                                if (isset($id3v2->apic)) {
                                        //workerLog('thmcache; mp3: id3v2: apic->imageData: length: ' . strlen($id3v2->apic->imageData));
                                        $image = outImage($id3v2->apic->mimeType, $id3v2->apic->imageData);
$image = false; // OVERRIDE DUE TO BUG ???
                                }
                        }

Seems another issue in Zend Framework ($id3v2->apic->imageData seems to contain four bytes of '0x00', confusing outImage() ? )


-Frank


RE: Thumbnail Generator Issue in 9.0.0 - ftw64 - 05-28-2024

Hi Tim,

I think this is as far as I can get with my poor knowledge of PHP.

I have added this code to /var/www/util/thumb-gen.php near line 319;


Code:
workerLog('thumb-gen: getImage(): 5');

                                if (isset($id3v2->apic)) {
                                        //workerLog('thmcache; mp3: id3v2: apic->imageData: length: ' . strlen($id3v2->apic->imageData));
workerLog('thumb-gen: getImage(): 10, imageData = |' . $id3v2->apic->imageData . '|' );
                                        $image = outImage($id3v2->apic->mimeType, $id3v2->apic->imageData);
workerLog('thumb-gen: getImage(): 11, image = |' . $image . '|');
// $image = false;
                                }
                        }

The last lines in moode.log read (when opening with vi to see the unprintable characters):


Code:
20240528 215710 thumb-gen: getImage(): 5
20240528 215710 thumb-gen: getImage(): 10, imageData = |^@^@^@^@|
20240528 215710 thumb-gen: outImage(): image/jpg, 4 bytes
20240528 215710 thumb-gen: getImage(): 11, image = |^@^@^@^@|

After that, the thumbnail generator seems to crash in file_get_contents() at line 168:


Code:
        if (strlen($imgStr) < 512) {
workerLog('thumb-gen: 11, imgStr = ' .$imgStr);
                //workerLog('thumb-gen: Image file: ' . $imgStr);
                $imgStr = file_get_contents($imgStr);
workerLog('thumb-gen: 12');
        }

Moode.log continues:


Code:
20240528 215710 thumb-gen: 10
20240528 215710 thumb-gen: 11, imgStr = ^@^@^@^@

But never prints 'thumb-gen: 12'.

I'm hoping for a solution as I really like MoOde Audio! It might be that the Zend Framework needs to be updated with PHP8?


With best regards,
-Frank


RE: Thumbnail Generator Issue in 9.0.0 - Nutul - 05-28-2024

This seems not the way to go...
It's either a malformed id3v2 tag (the Zend library should be fail-safe anyway...), or indeed the Zend library needs to be investigated more thoroughly for PHP8 compliancy.


RE: Thumbnail Generator Issue in 9.0.0 - Tim Curtis - 05-28-2024

Nice catch on the implode. I'll fix for upcoming r901. I also checked the code base for other implodes and they all look correct.

ETA: I'll look into the $image length issue based on your last post


RE: Thumbnail Generator Issue in 9.0.0 - Nutul - 05-28-2024

Also,
it could be that the Zend library is aware of the id3v2 tag up to version 3 (id3v2.3) and your files are tagged with version 4 (id3v2.4)
Just speculating here, cannot be sure; but as I discovered some inconsistencies in the Zend library about the id3 tag hadling in the past, it could well be something related.
You could try to check your files, and eventually try to convert the tag to version 3 (some tools, like kid3, can do it) and see if the problem gets solved.
Of course, if this is the case we can always "fix" the Zend library; but sometime in the future... ;-)


RE: Thumbnail Generator Issue in 9.0.0 - TheOldPresbyope - 05-28-2024

Sorry I've been MIA on this issue. Got a health scare soon after I downloaded the MP3 file from the OP (@haeckse ) and I've been spending time in waiting rooms . [To quote my grandmoter, who stole it from someone else I'm sure, "growing old is not for sissies." Oh well, it beats the alternative.]

As I read through @ftw64 's adventure digging in the bowels of Zend, I'm reminded that I found curiosities with the file jup.mp3. One is that it does not contain an APIC frame. The embedded coverart is apparently contained in a second MPEG stream. As well, outout of various tools such as ffprobe



Code:
...
[mp3 @ 0x5579135d8ec0] Skipping 835 bytes of junk at 29460.
---


and mp3diags


Code:
...
- WARNING: ID3V2 tag doesn't have an APIC frame (which is used to store images). [0]
- WARNING: File contains null streams. [29460]
...

A side effect of this is that my moOde 9.0.0. player doesn't display either a thumbnail or the full cover. I haven't had time to explore removing the second stream and writing the coverart instead in an APIC frame.

Regards,


RE: Thumbnail Generator Issue in 9.0.0 - TheOldPresbyope - 05-28-2024

Sorry I've been MIA on this issue. Got a health scare soon after I downloaded the MP3 file from the OP (@haeckse ) and I've been spending time in waiting rooms . [To quote my grandmoter, who stole it from someone else I'm sure, "growing old is not for sissies." Oh well, it beats the alternative.]

As I read through @ftw64 's adventure digging in the bowels of Zend, I'm reminded that I found curiosities with the file jup.mp3. One is that it does not contain an APIC frame. The embedded coverart is apparently contained in a second MPEG stream. As well, outout of various tools such as ffprobe



Code:
...
[mp3 @ 0x5579135d8ec0] Skipping 835 bytes of junk at 29460.
---


and mp3diags


Code:
...
- WARNING: ID3V2 tag doesn't have an APIC frame (which is used to store images). [0]
- WARNING: File contains null streams. [29460]
...

A side effect of this is that my moOde 9.0.0. player doesn't display either a thumbnail or the full cover. I haven't had time to explore removing the second stream and writing the coverart instead in an APIC frame.

Regards,
Kent


RE: Thumbnail Generator Issue in 9.0.0 - Tim Curtis - 05-28-2024

(05-28-2024, 08:06 PM)ftw64 Wrote: Hi Tim,

I think this is as far as I can get with my poor knowledge of PHP.

I have added this code to /var/www/util/thumb-gen.php near line 319;


Code:
workerLog('thumb-gen: getImage(): 5');

                                if (isset($id3v2->apic)) {
                                        //workerLog('thmcache; mp3: id3v2: apic->imageData: length: ' . strlen($id3v2->apic->imageData));
workerLog('thumb-gen: getImage(): 10, imageData = |' . $id3v2->apic->imageData . '|' );
                                        $image = outImage($id3v2->apic->mimeType, $id3v2->apic->imageData);
workerLog('thumb-gen: getImage(): 11, image = |' . $image . '|');
// $image = false;
                                }
                        }

The last lines in moode.log read (when opening with vi to see the unprintable characters):


Code:
20240528 215710 thumb-gen: getImage(): 5
20240528 215710 thumb-gen: getImage(): 10, imageData = |^@^@^@^@|
20240528 215710 thumb-gen: outImage(): image/jpg, 4 bytes
20240528 215710 thumb-gen: getImage(): 11, image = |^@^@^@^@|

After that, the thumbnail generator seems to crash in file_get_contents() at line 168:


Code:
        if (strlen($imgStr) < 512) {
workerLog('thumb-gen: 11, imgStr = ' .$imgStr);
                //workerLog('thumb-gen: Image file: ' . $imgStr);
                $imgStr = file_get_contents($imgStr);
workerLog('thumb-gen: 12');
        }

Moode.log continues:


Code:
20240528 215710 thumb-gen: 10
20240528 215710 thumb-gen: 11, imgStr = ^@^@^@^@

But never prints 'thumb-gen: 12'.

I'm hoping for a solution as I really like MoOde Audio! It might be that the Zend Framework needs to be updated with PHP8?


With best regards,
-Frank

It looks like nulls and any other bad data in the path arg for file_get_contents() causes crash.

Example: Crashing the php shell.


Code:
php > $tim = file_get_contents("\00");
PHP Warning:  Uncaught ValueError: file_get_contents(): Argument #1 ($filename) must not contain any null bytes in php shell code:1
Stack trace:
#0 php shell code(1): file_get_contents()
#1 {main}
 thrown in php shell code on line 1
php >

The fix is to check for a valid file path instead of using the assumption in the "if: statement that if length is < 512 it must be a path and not actual image data.


Code:
if (strlen($imgStr) < 512)

I'll fix for upcoming r901