$OpenBSD: patch-taglib_flac_flacfile_cpp,v 1.2 2013/01/27 21:28:25 dcoppa Exp $

Check if file is open before attempting to read tags: fix a crash
in the file constructor if the file does not exist
(upstream git commit d15c8453ac75d9070008b9170ae114ea31a4b586)

Corrupted FLAC files scan can result in heavy CPU consumption: fix
it by considering a file as being invalid if a 0 length block is
found (upstream git commit ad9ffc62e6fac5c47f46eb96b39c614e32742eb5)

--- taglib/flac/flacfile.cpp.orig	Thu Sep  6 20:03:15 2012
+++ taglib/flac/flacfile.cpp	Sun Jan 27 19:52:41 2013
@@ -108,7 +108,8 @@ FLAC::File::File(FileName file, bool readProperties,
   TagLib::File(file)
 {
   d = new FilePrivate;
-  read(readProperties, propertiesStyle);
+  if(isOpen())
+	read(readProperties, propertiesStyle);
 }
 
 FLAC::File::File(FileName file, ID3v2::FrameFactory *frameFactory,
@@ -117,7 +118,8 @@ FLAC::File::File(FileName file, ID3v2::FrameFactory *f
 {
   d = new FilePrivate;
   d->ID3v2FrameFactory = frameFactory;
-  read(readProperties, propertiesStyle);
+  if(isOpen())
+	read(readProperties, propertiesStyle);
 }
 
 FLAC::File::File(IOStream *stream, ID3v2::FrameFactory *frameFactory,
@@ -126,7 +128,8 @@ FLAC::File::File(IOStream *stream, ID3v2::FrameFactory
 {
   d = new FilePrivate;
   d->ID3v2FrameFactory = frameFactory;
-  read(readProperties, propertiesStyle);
+  if(isOpen())
+	read(readProperties, propertiesStyle);
 }
 
 FLAC::File::~File()
@@ -425,7 +428,7 @@ void FLAC::File::scan()
     length = header.mid(1, 3).toUInt();
 
     ByteVector data = readBlock(length);
-    if(data.size() != length) {
+    if(data.size() != length || length == 0) {
       debug("FLAC::File::scan() -- FLAC stream corrupted");
       setValid(false);
       return;
