Index: apps/codecs/libtremor/framing.c
===================================================================
--- apps/codecs/libtremor/framing.c	(revision 30701)
+++ apps/codecs/libtremor/framing.c	(arbetskopia)
@@ -236,7 +236,7 @@
 /* Helpers for ogg_stream_encode; this keeps the structure and
    what's happening fairly clear */
 
-static int _os_body_expand(ogg_stream_state *os,int needed){
+int _os_body_expand(ogg_stream_state *os,int needed){
   if(os->body_storage<=os->body_fill+needed){
     void *ret;
     ret=_ogg_realloc(os->body_data,(os->body_storage+needed+1024)*
@@ -783,7 +783,7 @@
 /* add the incoming page to the stream state; we decompose the page
    into packet segments here as well. */
 
-int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
+int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og,bool copy_body){
   unsigned char *header=og->header;
   unsigned char *body=og->body;
   long           bodysize=og->body_len;
@@ -868,8 +868,10 @@
   }
   
   if(bodysize){
-    if(_os_body_expand(os,bodysize)) return -1;
-    memcpy(os->body_data+os->body_fill,body,bodysize);
+    if(copy_body){
+      if(_os_body_expand(os,bodysize)) return -1;
+      memcpy(os->body_data+os->body_fill,body,bodysize);
+    }
     os->body_fill+=bodysize;
   }
 
Index: apps/codecs/libtremor/info.c
===================================================================
--- apps/codecs/libtremor/info.c	(revision 30701)
+++ apps/codecs/libtremor/info.c	(arbetskopia)
@@ -141,6 +141,7 @@
   return(OV_EBADHEADER);
 }
 
+#if 0
 static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
   int vendorlen;
   vendorlen=oggpack_read(opb,32);
@@ -156,6 +157,7 @@
   vorbis_comment_clear(vc);
   return(OV_EBADHEADER);
 }
+#endif
 
 /* all of the real encoding details are here.  The modes, books,
    everything */
@@ -269,6 +271,7 @@
 
 int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
   oggpack_buffer opb;
+  (void)vc;
   
   if(op){
     oggpack_readinit(&opb,op->packet,op->bytes);
@@ -303,10 +306,11 @@
           return(OV_EBADHEADER);
         }
 
-        return(_vorbis_unpack_comment(vc,&opb));
+        /*return(_vorbis_unpack_comment(vc,&opb));*/
+        return 0;
 
       case 0x05: /* least significant *bit* is read first */
-        if(vi->rate==0 || vc->vendor==NULL){
+        if(vi->rate==0 /*|| vc->vendor==NULL*/){
           /* um... we didn;t get the initial header or comments yet */
           return(OV_EBADHEADER);
         }
Index: apps/codecs/libtremor/vorbisfile.c
===================================================================
--- apps/codecs/libtremor/vorbisfile.c	(revision 30701)
+++ apps/codecs/libtremor/vorbisfile.c	(arbetskopia)
@@ -132,6 +132,25 @@
   }
 }
 
+/* This is a nasty hack to work around the huge allocations we get from
+   huge comment packets, usually due to embedded album art */
+static int ogg_stream_discard_packet(OggVorbis_File *vf,ogg_page *og,
+                                     ogg_int64_t boundary){
+  int ret;
+  while((ret = ogg_stream_packetout(&vf->os, NULL)) == 0) {
+    if(_get_next_page(vf, og, boundary)<0)
+      break;
+    ogg_stream_pagein(&vf->os,og,false);
+  }
+  if (ret < 0)
+    return -1;
+  if (vf->os.body_fill < og->body_len)
+    if(_os_body_expand(&vf->os, og->body_len))
+      return -1;
+  memcpy(vf->os.body_data+vf->os.body_fill-og->body_len, og->body, og->body_len);
+  return 1;
+}
+
 /* find the latest page beginning before the current stream cursor
    position. Much dirtier than the above as Ogg doesn't have any
    backward search linkage.  no 'readp' as it will certainly have to
@@ -312,7 +331,7 @@
       /* we don't have a vorbis stream in this link yet, so begin
          prospective stream setup. We need a stream to get packets */
       ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
-      ogg_stream_pagein(&vf->os,og_ptr);
+      ogg_stream_pagein(&vf->os,og_ptr,true);
 
       if(ogg_stream_packetout(&vf->os,&op) > 0 &&
          vorbis_synthesis_idheader(&op)){
@@ -340,7 +359,7 @@
       /* if this page also belongs to our vorbis stream, submit it and break */
       if(vf->ready_state==STREAMSET &&
          vf->os.serialno == ogg_page_serialno(og_ptr)){
-        ogg_stream_pagein(&vf->os,og_ptr);
+        ogg_stream_pagein(&vf->os,og_ptr,true);
         break;
       }
     }
@@ -354,10 +373,16 @@
   while(1){
 
     i=0;
+    /* discard comment packet */
+    if(ogg_stream_discard_packet(vf,og_ptr,CHUNKSIZE) < 0){
+      ret=OV_EBADHEADER;
+      goto bail_header;
+    }
+    i++;
+
     while(i<2){ /* get a page loop */
 
       while(i<2){ /* get a packet loop */
-
         int result=ogg_stream_packetout(&vf->os,&op);
         if(result==0)break;
         if(result==-1){
@@ -379,7 +404,7 @@
 
         /* if this page belongs to the correct stream, go parse it */
         if(vf->os.serialno == ogg_page_serialno(og_ptr)){
-          ogg_stream_pagein(&vf->os,og_ptr);
+          ogg_stream_pagein(&vf->os,og_ptr,true);
           break;
         }
 
@@ -428,7 +453,7 @@
     if(ogg_page_serialno(&og)!= serialno) continue;
 
     /* count blocksizes of all frames in the page */
-    ogg_stream_pagein(&vf->os,&og);
+    ogg_stream_pagein(&vf->os,&og,true);
     while((result=ogg_stream_packetout(&vf->os,&op))){
       if(result>0){ /* ignore holes */
         long thisblock=vorbis_packet_blocksize(vi,&op);
@@ -853,7 +878,7 @@
 
     /* the buffered page is the data we want, and we're ready for it;
        add it to the stream state */
-    ogg_stream_pagein(&vf->os,&og);
+    ogg_stream_pagein(&vf->os,&og,true);
 
   }
 }
@@ -1180,8 +1205,8 @@
         firstflag=(pagepos<=vf->dataoffsets[link]);
       }
 
-      ogg_stream_pagein(&vf->os,&og);
-      ogg_stream_pagein(&work_os,&og);
+      ogg_stream_pagein(&vf->os,&og,true);
+      ogg_stream_pagein(&work_os,&og,true);
       lastflag=ogg_page_eos(&og);
 
     }
@@ -1363,7 +1388,7 @@
       }
 
       ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
-      ogg_stream_pagein(&vf->os,&og);
+      ogg_stream_pagein(&vf->os,&og,true);
 
       /* pull out all but last packet; the one with granulepos */
       while(1){
@@ -1492,7 +1517,7 @@
         lastblock=0;
       }
 
-      ogg_stream_pagein(&vf->os,&og);
+      ogg_stream_pagein(&vf->os,&og,true);
     }
   }
 
Index: apps/codecs/libtremor/ogg.h
===================================================================
--- apps/codecs/libtremor/ogg.h	(revision 30701)
+++ apps/codecs/libtremor/ogg.h	(arbetskopia)
@@ -227,6 +227,8 @@
 #endif
 /* Ogg BITSTREAM PRIMITIVES: decoding **************************/
 
+extern int      _os_body_expand(ogg_stream_state *os,int needed);
+
 extern int      ogg_sync_init(ogg_sync_state *oy);
 extern int      ogg_sync_clear(ogg_sync_state *oy);
 extern int      ogg_sync_reset(ogg_sync_state *oy);
@@ -241,7 +243,7 @@
 /*
 extern int      ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
 */
-extern int      ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
+extern int      ogg_stream_pagein(ogg_stream_state *os, ogg_page *og, bool copy_body);
 extern int      ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
 extern int      ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
 
