Bug 15895 - Fails to scan some songs (Unable to read tags from file)
: Fails to scan some songs (Unable to read tags from file)
Status: RESOLVED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Scanner
: 7.6.0
: PC Ubuntu Linux
: P2 normal with 2 votes (vote)
: 7.6.0
Assigned To: Andy Grundman
: Audio::Scan
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-03-14 06:43 UTC by Iain Lane
Modified: 2011-08-14 00:24 UTC (History)
5 users (show)

See Also:
Category: ---


Attachments
Sample song which does not scan (7.62 MB, audio/mpeg)
2010-04-14 13:43 UTC, Iain Lane
Details
working here. (33.37 KB, image/jpeg)
2010-04-14 14:33 UTC, KDF
Details
zipped scanner.log (767.72 KB, application/octet-stream)
2011-07-01 19:47 UTC, Jim McAtee
Details
Song that fails to scan. (2.98 MB, audio/mpeg)
2011-07-15 05:01 UTC, wizkid2
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Iain Lane 2010-03-14 06:43:28 UTC
Hi,

I've noticed that not all songs are being added to my music library. This coincided with the squeezecenter/squeezeboxserver switch. From my logs:

[10-03-14 13:41:50.0229] Slim::Utils::Scanner::scanDirectory (333) Scanning: /home/laney/Music/cLOUDDEAD/Ten/04. The Velvet Ant.mp3
[10-03-14 13:41:50.0248] Slim::Utils::Scanner::scanDirectory (357) ERROR SCANNING /home/laney/Music/cLOUDDEAD/Ten/04. The Velvet Ant.mp3: Unable to read tags from file
[10-03-14 13:41:50.0250] Slim::Utils::Scanner::scanDirectory (333) Scanning: /home/laney/Music/The Mighty Mighty Bosstones/More Noise & Other Disturbance/01. Awfully Quiet.mp3
[10-03-14 13:41:50.0268] Slim::Utils::Scanner::scanDirectory (357) ERROR SCANNING /home/laney/Music/The Mighty Mighty Bosstones/More Noise & Other Disturbance/01. Awfully Quiet.mp3: Unable to read tags from file

...and so on.

I tried rewriting the tags of one of the affected files, even clearing and readding them, but it didn't help.

I can attach/mail a song if you'd like.

Iain
Comment 1 Iain Lane 2010-03-14 06:44:47 UTC
I am running the nightlies, by the way.
Comment 2 KDF 2010-04-14 13:32:36 UTC
please attach a sample song file for review.
Comment 3 Iain Lane 2010-04-14 13:43:35 UTC
Created attachment 6775 [details]
Sample song which does not scan

Yep, here's a broken one (also a good tune, enjoy!). Interestingly not all songs in the same album (so from the same rip) are broken. Probably about 30-40% of my music fails to scan in this way.
Comment 4 KDF 2010-04-14 14:33:45 UTC
Created attachment 6777 [details]
working here.

This is a capture of the scan results shown via browse.  I did not encounter any issues while using the 7.6 version (same as 7.5 embedded).  Either the problem is fixed in newer code or there is an issue on your system.

The error message you are seeing results from either the file being unreadable or the tag headers being corrupt.  Check the permissions on the problem files.  Make sure that they are readable for squeezeboxserver user.
Comment 5 Iain Lane 2011-02-18 01:35:19 UTC
Hello,

I'm here to provide an update on this, since I just got a new Radio and had to finally update from 7.4.

Now running r31915.

Lots and lots of songs still fail to scan. Here's a log excerpt.

[11-02-18 09:13:24.5514] Slim::Utils::Scanner::Local::new (634) Handling new track file:///home/laney/Music/Eva%20Cassidy/Time%20After%20Time/05.%20Time%20After%20Time.mp3
[11-02-18 09:13:24.5519] Slim::Utils::Misc::msg (1212) Warning: [09:13:24.5518] buffer_get_ret: trying to get more bytes 4 than in buffer 0 at /usr/share/squeezeboxserver/CPAN/Audio/Scan.pm line 64.
[11-02-18 09:13:24.5521] Slim::Formats::readTags (178) Error: While trying to ->getTag(/home/laney/Music/Eva Cassidy/Time After Time/05. Time After Time.mp3) : buffer_get_int_le: buffer error at /usr/share/squeezeboxserver/CPAN/Audio/Scan.pm line 64.
[11-02-18 09:13:24.5524] Slim::Formats::readTags (178) Backtrace:

   frame 0: Slim::Utils::Log::logBacktrace (/usr/share/perl5/Slim/Formats.pm line 178)
   frame 1: Slim::Formats::readTags (/usr/share/perl5/Slim/Schema.pm line 1486)
   frame 2: Slim::Schema::_newTrack (/usr/share/perl5/Slim/Schema.pm line 1819)
   frame 3: Slim::Schema::updateOrCreateBase (/usr/share/perl5/Slim/Utils/Scanner/Local.pm line 645)
   frame 4: Slim::Utils::Scanner::Local::__ANON__ (/usr/share/squeezeboxserver/CPAN/DBIx/Class/Storage/DBI.pm line 638)
   frame 5: (eval) (/usr/share/squeezeboxserver/CPAN/DBIx/Class/Storage/DBI.pm line 627)
   frame 6: DBIx::Class::Storage::DBI::txn_do (/usr/share/squeezeboxserver/lib/DBIx/Class/Schema.pm line 650)
   frame 7: DBIx::Class::Schema::txn_do (/usr/share/perl5/Slim/Utils/Scanner/Local.pm line 705)
   frame 8: Slim::Utils::Scanner::Local::new (/usr/share/perl5/Slim/Utils/Scanner/Local.pm line 307)
   frame 9: Slim::Utils::Scanner::Local::__ANON__ (/usr/share/perl5/Slim/Utils/Scheduler.pm line 150)
   frame 10: (eval) (/usr/share/perl5/Slim/Utils/Scheduler.pm line 150)
   frame 11: Slim::Utils::Scheduler::run_tasks (/usr/sbin/squeezeboxserver line 667)
   frame 12: main::idle (/usr/sbin/squeezeboxserver line 634)
   frame 13: main::main (/usr/sbin/squeezeboxserver line 1129)

[11-02-18 09:13:24.5525] Slim::Utils::Scanner::Local::__ANON__ (654) ERROR SCANNING file:///home/laney/Music/Eva%20Cassidy/Time%20After%20Time/05.%20Time%20After%20Time.mp3: Unable to read tags from file

I removed ID3v1 and v2 tags from this file and it still failed to scan in the same way.
Comment 6 wizkid2 2011-06-09 06:19:03 UTC
Hi,

I have got exactly the same problem as Iain Lane.
I'm running Squeezebox Server Version: 7.5.4 - r32171 @ Thu Apr 14 09:19:34 PDT 2011 on Windows XP SP3.

The problem is definitely not an access right problem, but related to certain conditions in the tags.
It can be fixed with MP3Tag in the following way:
1. Copy Tag
2. Remove Tag
3. Paste Tag
After this procedure the file with all its tags is scanned properly.
However it is practically impossible to go through this exercise with hundreds of files that are not recognised properly (about 50 percent of my files).

Squeezebox scanner is the only program that fails reading the original files/tags. None of the other applications that I use have a problem. This includes WinAmp, MediaMonkey, MP3Val, MP3Tag. They are all showing the tags without any error messages or difficulties.
So squeezebox scanner should be able to cope with it as well.

Could you please have a look. I can provide an example file if necessary.

Best Regards, Jürgen
Comment 7 Jim McAtee 2011-07-01 19:15:59 UTC
I see the same problem and have been seeing it for quite a while in both 7.5 and 7.6. I'm running SBS on a Windows server, not Ubuntu.

When a clear & rescan is run, anywhere from 900-1300 files in my library are skipped, with 'Unable to read tags from file' errors being logged to scanner.log. There's no sense in uploading any of the files, because each time the scan is run, it's a different number and a different set of files. There is nothing wrong with the files.

Running subsequent new & changed scans eventually picks up all of the missed files. It usually takes two or three additional new & changed scans to get them all.

The problem on my system is only with Flac files. Mp3 files are scanned 100%, with no errors.

Tonight I ran some additional tests. I have an Mp3 library that is a mirror of my Flac library. And I backup both the Flac and Mp3 libraries to an external USB drive. Trying to eliminate the possibility that the file errors were disk related, I set up two new 7.6 servers, one pointing at the backup Flac library, and one pointing at the backup Mp3 library, both on the USB drive.

The initial scan of the Mp3 library was 100%.

The initial scan of the Flac library skipped 971 files. Running a subsequent new & changed scan correctly scanned 947 of those files, and logged 24 'Unable to read tags from file' errors in server.log. A second new & changed scan picked up 20 of the 24, and a third try picked up the remaining 4 files.
Comment 8 Jim McAtee 2011-07-01 19:47:26 UTC
Created attachment 7328 [details]
zipped scanner.log

Here's a scanner.log for a clear & rescan of the Flac library with all scan.x logging set to debug. It scanned 30976 of 32338 files, so there should be 1362 'Unable to read tags from file' errors.
Comment 9 Adrian Smith 2011-07-02 02:22:33 UTC
Looks like the errors are due to:
[11-07-01 20:40:05.2629] Audio::Scan::scan (64) Warning: Error reading: No error (wanted 4096)

This comes from the following code in common.c:

 if ( (read = PerlIO_read(infile, tmp, actual_wanted)) <= 0 ) {
      if ( PerlIO_error(infile) ) {
        warn("Error reading: %s (wanted %d)\n", strerror(errno), actual_wanted);
      }
      else {
        warn("Error: Unable to read at least %d bytes from file.\n", min_wanted);
      }

      ret = 0;
      goto out;
    }

Is it possible that PerlIO_read is returning due to being interrupted by a signal and we are treating this as an error erroneously?  Don't know why errono is not set though - do we need to use GetLastError or is it reset by the PerlIO_error call?
Comment 10 Adrian Smith 2011-07-03 13:38:36 UTC
Looks like Jim's problem is different from the one at the start of this bug.

Jim's problem looks to be due to windows error 1450 - "Insufficient system resources exist to complete the requested service.  Hopefully some tuning of his server will make this go away."  (see http://support.microsoft.com/kb/304101/en-us)

We should add something to log the response from GetLastError on windows as the low level perl code uses ReadFile and this doesn't appear to set errno.

If tuning does not help Jim, then we may need to back off scanning for a few ms if we get that error?
Comment 11 Andy Grundman 2011-07-03 19:51:27 UTC
Thanks for debugging this, I'll see about building a version with Triode's patch. *insert random Windows-related grumbling here*
Comment 12 wizkid2 2011-07-09 04:58:21 UTC
Hi all,

I agree with Adrian that Jim's Problem is slightly different from the one that this bug originally related to.
There is no random behaviour in the way the scan fails with my audio files.
It is always the same set of files that is not scanned.

The log entry is always the same as well and looks like this:

[11-06-03 20:52:41.7063] Audio::Scan::scan (64) Warning: buffer_get_ret: trying to get more bytes 4 than in buffer 0 at /<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Audio/Scan.pm line 64.
[11-06-03 20:52:41.7066] Slim::Formats::readTags (178) Error: While trying to ->getTag(C:\Documents and Settings\jmayerho\My Documents\JM\Music\Play\Moods\Fast\Adventurous\Chequered Love\Shakira - Suerte (Whenever, Wherever).mp3) : buffer_get_int_le: buffer error at /<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Audio/Scan.pm line 64.
[11-06-03 20:52:41.7069] Slim::Formats::readTags (178) Backtrace:

   frame 0: Slim::Utils::Log::logBacktrace (/<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Slim/Formats.pm line 178)
   frame 1: Slim::Formats::readTags (/<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Slim/Schema.pm line 937)
   frame 2: Slim::Schema::newTrack (/<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Slim/Utils/Scanner.pm line 347)
   frame 3: Slim::Utils::Scanner::scanDirectory (/<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Slim/Music/MusicFolderScan.pm line 79)
   frame 4: Slim::Music::MusicFolderScan::startScan (/<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Slim/Music/Import.pm line 568)
   frame 5: Slim::Music::Import::runImporter (/<C:\PROGRA~1\SQUEEZ~1\server\scanner.exe>Slim/Music/Import.pm line 373)
   frame 6: Slim::Music::Import::runScan (scanner.pl line 305)
   frame 7: (eval) (scanner.pl line 299)
   frame 8: main::main (scanner.pl line 454)

@ Adrian, Andy:
While you are looking at Jim's problem, would it be possible to look at the original problem that Ian and I had as well? I would very much appreciate this as I can only play half of my files using Squeezebox Server.

Best Regards, Jürgen
Comment 13 Adrian Smith 2011-07-09 07:50:57 UTC
I've tested the file attached by Ian with both Linux and Windows and I can scan in both cases with the latest 7.6.  Can you confirm you are still seeing the problem and attach a file with the problem if it is different from the one attached here.
Comment 14 SVN Bot 2011-07-14 10:05:53 UTC
 == Auto-comment from SVN commit #32706 to the slim repo by agrundman ==
 == http://svn.slimdevices.com/slim?view=revision&revision=32706 ==

Bug 15895, Rebuilt Audio::Scan 0.87 with Triode's Windows error message patch
Comment 15 Andy Grundman 2011-07-14 10:07:06 UTC
Please let me know if this helps, guys.
Comment 16 wizkid2 2011-07-15 05:01:25 UTC
Created attachment 7333 [details]
Song that fails to scan.

Hi Adrian,

I just scanned my files with the latest version of Squeezebox Server:
   Version: 7.5.5 - r32671 @ Mon Jul 11 12:00:49 PDT 2011

The problem still exists.
Please find attached one of the files that fail to scan (the Shakira song that produced the error log entry that I posted in one of my previous comments).

Thanks for your help.
Jürgen
Comment 17 Adrian Smith 2011-07-15 09:48:34 UTC
Andy - this file does cause a problem.  It looks to be due to ape field parsing running off the end of the buffer.  I don't understand at present where the code checks that it has enough buffered data to read all the ape fields - perhaps you could look.  Here's the debug output with a backtrace at the point the error occurs:

adrian@mac:~/squeezecenter/Audio-Scan$ ./test.pl
problem.mp3
Buffer allocated with 4096 bytes
Buffering from file @ 0 (min_wanted 10, max_wanted 4096, adjusted to 4096)
Buffered 4096 bytes, new pos 4096
Found ID3v2.3.0 tag, size 9201
  seeked past 9201 bytes to 9201
Buffering from file @ 9201 (min_wanted 4, max_wanted 4096, adjusted to 4096)
Buffered 4096 bytes, new pos 13297
Found FF sync at offset 9201
Frame @9c06a3c: size=417, 1152 samples, 128kbps 44100/2
Frame @9c06bdd: size=417, 1152 samples, 128kbps 44100/2
Frame @9c06d7e: size=418, 1152 samples, 128kbps 44100/2
  valid frame
Found Xing/Info tag
bitrate from lame_abr_rate: 128
ID3v1 tag found
Buffer high water mark: 4096
Seeked to 3125840 looking for APE tag
Buffer allocated with 136 bytes
Buffering from file @ 3125840 (min_wanted 136, max_wanted 136, adjusted to 136)
Buffered 136 bytes, new pos 3125976
APE tag found at -160 (with ID3v1)
Buffer high water mark: 136
Buffer allocated with 32 bytes
Buffering from file @ 3125840 (min_wanted 32, max_wanted 32, adjusted to 32)
Buffered 32 bytes, new pos 3125872
Found APEv2 tag, size 8310 with 13 items
APE tag offset 3117562
Buffer allocated with 32 bytes
Buffer allocated with 8246 bytes
Buffering from file @ 3117562 (min_wanted 32, max_wanted 32, adjusted to 32)
Buffered 32 bytes, new pos 3117594
Buffering from file @ 3117594 (min_wanted 8246, max_wanted 8246, adjusted to 8246)
Buffered 8246 bytes, new pos 3125840
Reduced audio_size value by APE/Lyrics2 tag size 8310
key_length: 14 / val_length: 8 / size: 7 / flags 0 @ 3117617
  MP3GAIN_MINMAX = 123,203
key_length: 12 / val_length: 12 / size: 11 / flags 0 @ 3117645
  MP3GAIN_UNDO = +006,+006,N
key_length: 21 / val_length: 13 / size: 12 / flags 0 @ 3117686
  REPLAYGAIN_TRACK_GAIN = -0.210000 dB
key_length: 21 / val_length: 9 / size: 8 / flags 0 @ 3117728
  REPLAYGAIN_TRACK_PEAK = 0.505601
key_length: 6 / val_length: 8 / size: 7 / flags 0 @ 3117751
  ARTIST = Shakira
key_length: 5 / val_length: 16 / size: 15 / flags 0 @ 3117772
  ALBUM = Laundry Service
key_length: 5 / val_length: 28 / size: 27 / flags 0 @ 3117801
  TITLE = Suerte (Whenever, Wherever)
key_length: 5 / val_length: 3 / size: 2 / flags 0 @ 3117842
  TRACK = 12
key_length: 4 / val_length: 5 / size: 4 / flags 0 @ 3117857
  YEAR = 2000
key_length: 5 / val_length: 6 / size: 5 / flags 0 @ 3117875
  GENRE = latin
key_length: 17 / val_length: 9 / size: 7934 / flags 2 @ 3117906
buffer_get_ret: trying to get more bytes 4 than in buffer 0 at blib/lib/Audio/Scan.pm line 64.
Obtained 10 stack frames.
./blib/arch/auto/Audio/Scan/Scan.so(buffer_get_int_le+0x54) [0xb749b884]
./blib/arch/auto/Audio/Scan/Scan.so(_ape_parse_field+0x35) [0xb749ca65]
./blib/arch/auto/Audio/Scan/Scan.so(_ape_parse_fields+0x38) [0xb749d1e8]
./blib/arch/auto/Audio/Scan/Scan.so(_ape_parse+0x59) [0xb74ab569]
./blib/arch/auto/Audio/Scan/Scan.so(+0x1f5f6) [0xb74ab5f6]
./blib/arch/auto/Audio/Scan/Scan.so(get_mp3tags+0x68) [0xb74c0418]
./blib/arch/auto/Audio/Scan/Scan.so(XS_Audio__Scan__scan+0x7e1) [0xb74b7f01]
/usr/bin/perl(Perl_pp_entersub+0x52b) [0x80d198b]
/usr/bin/perl(Perl_runops_standard+0x18) [0x80cfd58]
/usr/bin/perl(perl_run+0x342) [0x8078b22]
buffer_get_int_le: buffer error at blib/lib/Audio/Scan.pm line 64.
Comment 18 Andy Grundman 2011-07-15 09:58:05 UTC
OK those types of problems are easy to deal with.
Comment 19 Jim McAtee 2011-07-15 13:14:46 UTC
It might be good to know which application tagged this file. It's interesting that I can retag the file in Mp3tag, keeping the APE tag, and SBS will scan it OK. So it's not simply because the file has an APE tag, but something specific about how it's being written to the file.

FWIW, I've suspected that the scanner crashing problems being widely reported may also be due to APE tag handling. There seems to be some anecdotal evidence of this in the reports being made within the forums.
Comment 20 Andy Grundman 2011-07-15 13:20:32 UTC
This is not a crash though, just a song that is not scanned because of a (possibly) invalid tag.
Comment 21 Jim McAtee 2011-07-15 13:29:30 UTC
Right. I'm just saying that I think problems with the handling of APE tags may go beyond just this case. Once this bug is fixed, maybe it would be helpful to ask users with crashing problems to test the new scanner. Or when you fix this bug, perhaps look a bit more closely at overall APE tag handling and see if you can discover any other issues.
Comment 22 Adrian Smith 2011-07-20 14:23:41 UTC
This problem file seems to claim more tag items than exist, I can parse the file with the following patch:

Index: src/ape.c
===================================================================
--- src/ape.c   (revision 867)
+++ src/ape.c   (working copy)
@@ -161,7 +161,7 @@
   tag->size         = buffer_get_int_le(&tag->tag_footer);
   tag->item_count   = buffer_get_int_le(&tag->tag_footer);
   tag->footer_flags = buffer_get_int_le(&tag->tag_footer);
-  tag->size += APE_TAG_FOOTER_LEN;
+  tag->size += APE_TAG_HEADER_LEN;
   data_size = tag->size - APE_TAG_HEADER_LEN - APE_TAG_FOOTER_LEN;
   
   DEBUG_TRACE("Found APEv%d tag, size %d with %d items\n", tag->version, tag->size, tag->item_count);
@@ -289,6 +289,10 @@
   unsigned char *tmp_ptr;
   SV *key = NULL;
   SV *value = NULL;
+
+  if (buffer_len(&tag->tag_data) < 8) {
+         return _ape_error(tag, "No more data to parse but specified number of items not found", -999999);
+  }
   
   size  = buffer_get_int_le(&tag->tag_data);
   flags = buffer_get_int_le(&tag->tag_data);


[not sure what the error numbering scheme is Andy - assume this needs a new error??]
Comment 23 Andy Grundman 2011-08-03 09:26:39 UTC
Thanks. Did you mean to make the earlier change from FOOTER_LEN to HEADER_LEN? The error codes are a relic and don't matter.
Comment 24 Adrian Smith 2011-08-03 09:32:48 UTC
Its moot as FOOTER_LEN and HEADER_LEN are the same, but I think the logic is such that it should be the header length.  The field read is the "Tag size in bytes including footer and all tag items excluding the header" according to:

http://wiki.hydrogenaudio.org/index.php?title=APE_Tags_Header

so the total size should be this + the header size.emacs
Comment 25 SVN Bot 2011-08-03 09:46:53 UTC
 == Auto-comment from SVN commit #872 to the opensource repo by agrundman ==
 == http://svn.slimdevices.com/opensource?view=revision&revision=872 ==

Fixed bug 15895, better handling if we have a broken APE tag and run out of tag data
Comment 26 Andy Grundman 2011-08-03 13:57:56 UTC
Please test with 7.6.1 build 32962 or later.
Comment 27 wizkid2 2011-08-14 00:24:35 UTC
I've tested with 7.6.1 build 32962 on Windows XP.
The fix resolved the problem and all my files are now scanned and added to the library (although there are still some strange effects, but not related to this bug).
Thanks for resolving this! You've made my day!
Best Regards, Jürgen