diff --git a/media/libogg/src/ogg_framing.c b/media/libogg/src/ogg_framing.c
index 3a2f0a605..79fc715c8 100644
--- a/media/libogg/src/ogg_framing.c
+++ b/media/libogg/src/ogg_framing.c
@@ -12,7 +12,7 @@
 
  function: code raw packets into framed OggSquish stream and
            decode Ogg streams back into raw packets
- last mod: $Id: framing.c 18758 2013-01-08 16:29:56Z tterribe $
+ last mod: $Id$
 
  note: The CRC code is directly derived from public domain code by
  Ross Williams (ross@guest.adelaide.edu.au).  See docs/framing.html
@@ -875,6 +875,7 @@ int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
      some segments */
   if(continued){
     if(os->lacing_fill<1 ||
+       (os->lacing_vals[os->lacing_fill-1]&0xff)<255 ||
        os->lacing_vals[os->lacing_fill-1]==0x400){
       bos=0;
       for(;segptr<segments;segptr++){
@@ -1492,6 +1493,34 @@ const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
                        1,
                        0};
 
+int compare_packet(const ogg_packet *op1, const ogg_packet *op2){
+  if(op1->packet!=op2->packet){
+    fprintf(stderr,"op1->packet != op2->packet\n");
+    return(1);
+  }
+  if(op1->bytes!=op2->bytes){
+    fprintf(stderr,"op1->bytes != op2->bytes\n");
+    return(1);
+  }
+  if(op1->b_o_s!=op2->b_o_s){
+    fprintf(stderr,"op1->b_o_s != op2->b_o_s\n");
+    return(1);
+  }
+  if(op1->e_o_s!=op2->e_o_s){
+    fprintf(stderr,"op1->e_o_s != op2->e_o_s\n");
+    return(1);
+  }
+  if(op1->granulepos!=op2->granulepos){
+    fprintf(stderr,"op1->granulepos != op2->granulepos\n");
+    return(1);
+  }
+  if(op1->packetno!=op2->packetno){
+    fprintf(stderr,"op1->packetno != op2->packetno\n");
+    return(1);
+  }
+  return(0);
+}
+
 void test_pack(const int *pl, const int **headers, int byteskip,
                int pageskip, int packetskip){
   unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
@@ -1600,7 +1629,7 @@ void test_pack(const int *pl, const int **headers, int byteskip,
               ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
 
               /* verify peek and out match */
-              if(memcmp(&op_de,&op_de2,sizeof(op_de))){
+              if(compare_packet(&op_de,&op_de2)){
                 fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
                         depacket);
                 exit(1);
diff --git a/media/libtheora/lib/decinfo.c b/media/libtheora/lib/decinfo.c
index 603b1f93e..064bde437 100644
--- a/media/libtheora/lib/decinfo.c
+++ b/media/libtheora/lib/decinfo.c
@@ -174,7 +174,23 @@ static int oc_dec_headerin(oc_pack_buf *_opb,th_info *_info,
   packtype=(int)val;
   /*If we're at a data packet and we have received all three headers, we're
      done.*/
-  if(!(packtype&0x80)&&_info->frame_width>0&&_tc->vendor!=NULL&&*_setup!=NULL){
+  /*If we're at a data packet...*/
+  if(!(packtype&0x80)){
+    /*Check to make sure we received all three headers...
+      If we haven't seen any valid headers, assume this is not actually
+       Theora.*/
+    if(_info->frame_width<=0)return TH_ENOTFORMAT;
+    /*Follow our documentation, which says we'll return TH_EFAULT if this
+       are NULL (_info was checked by our caller).*/
+    if(_tc==NULL)return TH_EFAULT;
+    /*And if any other headers were missing, declare this packet "out of
+       sequence" instead.*/
+    if(_tc->vendor==NULL)return TH_EBADHEADER;
+    /*Don't check this until it's needed, since we allow passing NULL for the
+       arguments that we're not expecting the next header to fill in yet.*/
+    if(_setup==NULL)return TH_EFAULT;
+    if(*_setup==NULL)return TH_EBADHEADER;
+    /*If we got everything, we're done.*/
     return 0;
   }
   /*Check the codec string.*/
diff --git a/media/libtheora/lib/decode.c b/media/libtheora/lib/decode.c
index 563782b7a..a3fa57c5d 100644
--- a/media/libtheora/lib/decode.c
+++ b/media/libtheora/lib/decode.c
@@ -2705,8 +2705,8 @@ int th_decode_ycbcr_out(th_dec_ctx *_dec,th_ycbcr_buffer _ycbcr){
                 }break;
                 /*Plus:*/
                 case 1:{
-                  if(bi&2==0)yp-=2;
-                  if(bi&1==0)xp-=2;
+                  if((bi&2)==0)yp-=2;
+                  if((bi&1)==0)xp-=2;
                   cairo_move_to(c,xp+4.5,yp+2.5);
                   cairo_line_to(c,xp+4.5,yp+6.5);
                   cairo_move_to(c,xp+2.5,yp+4.5);
diff --git a/media/libtheora/lib/internal.c b/media/libtheora/lib/internal.c
index 1b2611da1..2cde48210 100644
--- a/media/libtheora/lib/internal.c
+++ b/media/libtheora/lib/internal.c
@@ -131,7 +131,6 @@ void **oc_malloc_2d(size_t _height,size_t _width,size_t _sz){
   datsz=rowsz*_height;
   /*Alloc array and row pointers.*/
   ret=(char *)_ogg_malloc(datsz+colsz);
-  if(ret==NULL)return NULL;
   /*Initialize the array.*/
   if(ret!=NULL){
     size_t   i;
@@ -154,7 +153,6 @@ void **oc_calloc_2d(size_t _height,size_t _width,size_t _sz){
   datsz=rowsz*_height;
   /*Alloc array and row pointers.*/
   ret=(char *)_ogg_calloc(datsz+colsz,1);
-  if(ret==NULL)return NULL;
   /*Initialize the array.*/
   if(ret!=NULL){
     size_t   i;
diff --git a/media/libtheora/lib/state.c b/media/libtheora/lib/state.c
index 5e7b0ae65..4fed213c1 100644
--- a/media/libtheora/lib/state.c
+++ b/media/libtheora/lib/state.c
@@ -253,10 +253,14 @@ static void oc_mb_fill_cmapping10(oc_mb_map_plane _mb_map[3],
   This version is for use with no chroma decimation (4:4:4).
   This uses the already filled-in luma plane values.
   _mb_map:  The macro block map to fill.
-  _fplanes: The descriptions of the fragment planes.*/
+  _fplanes: The descriptions of the fragment planes.
+  _xfrag0:  The X location of the upper-left hand fragment in the luma plane.
+  _yfrag0:  The Y location of the upper-left hand fragment in the luma plane.*/
 static void oc_mb_fill_cmapping11(oc_mb_map_plane _mb_map[3],
- const oc_fragment_plane _fplanes[3]){
+ const oc_fragment_plane _fplanes[3],int _xfrag0,int _yfrag0){
   int k;
+  (void)_xfrag0;
+  (void)_yfrag0;
   for(k=0;k<4;k++){
     _mb_map[1][k]=_mb_map[0][k]+_fplanes[1].froffset;
     _mb_map[2][k]=_mb_map[0][k]+_fplanes[2].froffset;
@@ -278,7 +282,7 @@ static const oc_mb_fill_cmapping_func OC_MB_FILL_CMAPPING_TABLE[4]={
   oc_mb_fill_cmapping00,
   oc_mb_fill_cmapping01,
   oc_mb_fill_cmapping10,
-  (oc_mb_fill_cmapping_func)oc_mb_fill_cmapping11
+  oc_mb_fill_cmapping11
 };
 
 /*Fills in the mapping from macro blocks to their corresponding fragment
diff --git a/media/libtremor/lib/misc.h b/media/libtremor/lib/misc.h
index 2fc521a24..1ae4d2e81 100644
--- a/media/libtremor/lib/misc.h
+++ b/media/libtremor/lib/misc.h
@@ -49,7 +49,9 @@ union magic {
   } halves;
   ogg_int64_t whole;
 };
-#elif BYTE_ORDER==BIG_ENDIAN
+#endif 
+
+#if BYTE_ORDER==BIG_ENDIAN
 union magic {
   struct {
     ogg_int32_t hi;
diff --git a/media/libtremor/lib/tremor_codebook.c b/media/libtremor/lib/tremor_codebook.c
index f8b798384..1e1ae8a91 100644
--- a/media/libtremor/lib/tremor_codebook.c
+++ b/media/libtremor/lib/tremor_codebook.c
@@ -258,7 +258,7 @@ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
 	t[i] = book->valuelist+entry[i]*book->dim;
       }
       for(i=0,o=0;i<book->dim;i++,o+=step)
-	for (j=0;j<step;j++)
+	for (j=0;o+j<n && j<step;j++)
 	  a[o+j]+=t[j][i]>>shift;
     }else{
       for (i = 0; i < step; i++) {
@@ -267,7 +267,7 @@ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
 	t[i] = book->valuelist+entry[i]*book->dim;
       }
       for(i=0,o=0;i<book->dim;i++,o+=step)
-	for (j=0;j<step;j++)
+	for (j=0;o+j<n && j<step;j++)
 	  a[o+j]+=t[j][i]<<-shift;
     }
   }
@@ -287,7 +287,7 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
 	entry = decode_packed_entry_number(book,b);
 	if(entry==-1)return(-1);
 	t     = book->valuelist+entry*book->dim;
-	for (j=0;j<book->dim;)
+	for (j=0;i<n && j<book->dim;)
 	  a[i++]+=t[j++]>>shift;
       }
     }else{
@@ -295,7 +295,7 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
 	entry = decode_packed_entry_number(book,b);
 	if(entry==-1)return(-1);
 	t     = book->valuelist+entry*book->dim;
-	for (j=0;j<book->dim;)
+	for (j=0;i<n && j<book->dim;)
 	  a[i++]+=t[j++]<<-shift;
       }
     }
@@ -352,15 +352,15 @@ long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,\
     long i,j,entry;
     int chptr=0;
     int shift=point-book->binarypoint;
-    
+    int m=offset+n;
     if(shift>=0){
       
-      for(i=offset;i<offset+n;){
+      for(i=offset;i<m;){
 	entry = decode_packed_entry_number(book,b);
 	if(entry==-1)return(-1);
 	{
 	  const ogg_int32_t *t = book->valuelist+entry*book->dim;
-	  for (j=0;j<book->dim;j++){
+	  for (j=0;i<m && j<book->dim;j++){
 	    a[chptr++][i]+=t[j]>>shift;
 	    if(chptr==ch){
 	      chptr=0;
@@ -371,12 +371,12 @@ long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,\
       }
     }else{
       
-      for(i=offset;i<offset+n;){
+      for(i=offset;i<m;){
 	entry = decode_packed_entry_number(book,b);
 	if(entry==-1)return(-1);
 	{
 	  const ogg_int32_t *t = book->valuelist+entry*book->dim;
-	  for (j=0;j<book->dim;j++){
+	  for (j=0;i<m && j<book->dim;j++){
 	    a[chptr++][i]+=t[j]<<-shift;
 	    if(chptr==ch){
 	      chptr=0;
diff --git a/media/libtremor/lib/tremor_floor0.c b/media/libtremor/lib/tremor_floor0.c
index 9f3ef5601..964383eff 100644
--- a/media/libtremor/lib/tremor_floor0.c
+++ b/media/libtremor/lib/tremor_floor0.c
@@ -328,6 +328,7 @@ static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
     info->books[j]=oggpack_read(opb,8);
     if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
     if(ci->book_param[info->books[j]]->maptype==0)goto err_out;
+    if(ci->book_param[info->books[j]]->dim<1)goto err_out;
   }
   return(info);
 
diff --git a/media/libtremor/lib/tremor_floor1.c b/media/libtremor/lib/tremor_floor1.c
index 12a687ec5..e63ae9fb3 100644
--- a/media/libtremor/lib/tremor_floor1.c
+++ b/media/libtremor/lib/tremor_floor1.c
@@ -426,7 +426,7 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
     int hx=0;
     int lx=0;
     int ly=fit_value[0]*info->mult;
-    /* guard lookup against out-of-rage values */
+    /* guard lookup against out-of-range values */
     ly=(ly<0?0:ly>255?255:ly);
 
     for(j=1;j<look->posts;j++){
@@ -436,10 +436,9 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
 	
 	hx=info->postlist[current];
 	hy*=info->mult;
-        /* guard lookup against out-of-rage values */
+        /* guard lookup against out-of-range values */
         hy=(hy<0?0:hy>255?255:hy);
 
-
 	render_line(n,lx,hx,ly,hy,out);
 	
 	lx=hx;
diff --git a/media/libtremor/lib/tremor_info.c b/media/libtremor/lib/tremor_info.c
index 3f3308ef9..24e24ac72 100644
--- a/media/libtremor/lib/tremor_info.c
+++ b/media/libtremor/lib/tremor_info.c
@@ -227,7 +227,6 @@ static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
 static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
   int i;
-  if(!ci)return(OV_EFAULT);
 
   /* codebooks */
   ci->books=oggpack_read(opb,8)+1;
@@ -367,6 +366,10 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
 	  /* um... we didn't get the initial header */
 	  return(OV_EBADHEADER);
 	}
+        if(vc->vendor!=NULL){
+          /* previously initialized comment header */
+          return(OV_EBADHEADER);
+        }
 
 	return(_vorbis_unpack_comment(vc,&opb));
 
@@ -375,6 +378,14 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
 	  /* um... we didn;t get the initial header or comments yet */
 	  return(OV_EBADHEADER);
 	}
+        if(vi->codec_setup==NULL){
+          /* improperly initialized vorbis_info */
+          return(OV_EFAULT);
+        }
+        if(((codec_setup_info *)vi->codec_setup)->books>0){
+          /* previously initialized setup header */
+          return(OV_EBADHEADER);
+        }
 
 	return(_vorbis_unpack_books(vi,&opb));
 
diff --git a/media/libtremor/lib/tremor_mdct.c b/media/libtremor/lib/tremor_mdct.c
index 4f39e7d53..2aed62c51 100644
--- a/media/libtremor/lib/tremor_mdct.c
+++ b/media/libtremor/lib/tremor_mdct.c
@@ -13,7 +13,7 @@
 
  function: normalized modified discrete cosine transform
            power of two length transform only [64 <= n ]
- last mod: $Id: mdct.c,v 1.9 2002/10/16 09:17:39 xiphmont Exp $
+ last mod: $Id$
 
  Original algorithm adapted long ago from _The use of multirate filter
  banks for coding of high quality digital audio_, by T. Sporer,
diff --git a/media/libtremor/lib/tremor_synthesis.c b/media/libtremor/lib/tremor_synthesis.c
index c7680f6d0..d22cb823c 100644
--- a/media/libtremor/lib/tremor_synthesis.c
+++ b/media/libtremor/lib/tremor_synthesis.c
@@ -67,7 +67,7 @@ static int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){
   
   /* more setup */
   vb->granulepos=op->granulepos;
-  vb->sequence=op->packetno-3; /* first block is third packet */
+  vb->sequence=op->packetno; /* first block is third packet */
   vb->eofflag=op->e_o_s;
 
   if(decodep){
diff --git a/media/libvorbis/include/vorbis/codec.h b/media/libvorbis/include/vorbis/codec.h
index 999aa3351..42aa29138 100644
--- a/media/libvorbis/include/vorbis/codec.h
+++ b/media/libvorbis/include/vorbis/codec.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec.h 17021 2010-03-24 09:29:41Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/include/vorbis/vorbisenc.h b/media/libvorbis/include/vorbis/vorbisenc.h
index 02332b50c..55f3b4a66 100644
--- a/media/libvorbis/include/vorbis/vorbisenc.h
+++ b/media/libvorbis/include/vorbis/vorbisenc.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: vorbis encode-engine setup
- last mod: $Id: vorbisenc.h 17021 2010-03-24 09:29:41Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/backends.h b/media/libvorbis/lib/backends.h
index ff5bcc95f..22809d46d 100644
--- a/media/libvorbis/lib/backends.h
+++ b/media/libvorbis/lib/backends.h
@@ -12,7 +12,6 @@
 
  function: libvorbis backend and mapping structures; needed for
            static mode headers
- last mod: $Id: backends.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/bitrate.h b/media/libvorbis/lib/bitrate.h
index db48fcb64..655a68cc0 100644
--- a/media/libvorbis/lib/bitrate.h
+++ b/media/libvorbis/lib/bitrate.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: bitrate tracking and management
- last mod: $Id: bitrate.h 13293 2007-07-24 00:09:47Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/books/coupled/res_books_51.h b/media/libvorbis/lib/books/coupled/res_books_51.h
index 93910ff48..47df4b221 100644
--- a/media/libvorbis/lib/books/coupled/res_books_51.h
+++ b/media/libvorbis/lib/books/coupled/res_books_51.h
@@ -11,7 +11,6 @@
  ********************************************************************
  *
  * function: static codebooks for 5.1 surround
- * last modified: $Id: res_books_51.h 19057 2014-01-22 12:32:31Z xiphmont $
  *
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/books/coupled/res_books_stereo.h b/media/libvorbis/lib/books/coupled/res_books_stereo.h
index 9a9049f6e..61d934046 100644
--- a/media/libvorbis/lib/books/coupled/res_books_stereo.h
+++ b/media/libvorbis/lib/books/coupled/res_books_stereo.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: static codebooks autogenerated by huff/huffbuld
- last modified: $Id: res_books_stereo.h 19057 2014-01-22 12:32:31Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/books/floor/floor_books.h b/media/libvorbis/lib/books/floor/floor_books.h
index e925313f7..67d5f31a3 100644
--- a/media/libvorbis/lib/books/floor/floor_books.h
+++ b/media/libvorbis/lib/books/floor/floor_books.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: static codebooks autogenerated by huff/huffbuld
- last modified: $Id: floor_books.h 19057 2014-01-22 12:32:31Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/books/uncoupled/res_books_uncoupled.h b/media/libvorbis/lib/books/uncoupled/res_books_uncoupled.h
index 736353b67..3d658ec47 100644
--- a/media/libvorbis/lib/books/uncoupled/res_books_uncoupled.h
+++ b/media/libvorbis/lib/books/uncoupled/res_books_uncoupled.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: static codebooks autogenerated by huff/huffbuld
- last modified: $Id: res_books_uncoupled.h 19057 2014-01-22 12:32:31Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/codebook.h b/media/libvorbis/lib/codebook.h
index 537d6c12d..08440c696 100644
--- a/media/libvorbis/lib/codebook.h
+++ b/media/libvorbis/lib/codebook.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: codebook.h 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/codec_internal.h b/media/libvorbis/lib/codec_internal.h
index de1bccaed..e522be18d 100644
--- a/media/libvorbis/lib/codec_internal.h
+++ b/media/libvorbis/lib/codec_internal.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec_internal.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/envelope.h b/media/libvorbis/lib/envelope.h
index fd15fb32a..f466efde8 100644
--- a/media/libvorbis/lib/envelope.h
+++ b/media/libvorbis/lib/envelope.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/highlevel.h b/media/libvorbis/lib/highlevel.h
index e38f370fd..337b75bfa 100644
--- a/media/libvorbis/lib/highlevel.h
+++ b/media/libvorbis/lib/highlevel.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: highlevel encoder setup struct separated out for vorbisenc clarity
- last mod: $Id: highlevel.h 17195 2010-05-05 21:49:51Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/lookup.h b/media/libvorbis/lib/lookup.h
index f8b5b8273..4bc0f3a20 100644
--- a/media/libvorbis/lib/lookup.h
+++ b/media/libvorbis/lib/lookup.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: lookup based functions
-  last mod: $Id: lookup.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/lookup_data.h b/media/libvorbis/lib/lookup_data.h
index 2424a1b38..5de3cfdc7 100644
--- a/media/libvorbis/lib/lookup_data.h
+++ b/media/libvorbis/lib/lookup_data.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: lookup data; generated by lookups.pl; edit there
-  last mod: $Id: lookup_data.h 16037 2009-05-26 21:10:58Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/lpc.h b/media/libvorbis/lib/lpc.h
index 39d237601..9cc79451b 100644
--- a/media/libvorbis/lib/lpc.h
+++ b/media/libvorbis/lib/lpc.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: LPC low level routines
-  last mod: $Id: lpc.h 16037 2009-05-26 21:10:58Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/lsp.h b/media/libvorbis/lib/lsp.h
index bacfb0971..8a8d10e97 100644
--- a/media/libvorbis/lib/lsp.h
+++ b/media/libvorbis/lib/lsp.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: LSP (also called LSF) conversion routines
-  last mod: $Id: lsp.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/masking.h b/media/libvorbis/lib/masking.h
index 3576ab788..955e18c71 100644
--- a/media/libvorbis/lib/masking.h
+++ b/media/libvorbis/lib/masking.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: masking curve data for psychoacoustics
- last mod: $Id: masking.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/mdct.h b/media/libvorbis/lib/mdct.h
index 3ed94333c..3b8c9ba4a 100644
--- a/media/libvorbis/lib/mdct.h
+++ b/media/libvorbis/lib/mdct.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: modified discrete cosine transform prototypes
- last mod: $Id: mdct.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/misc.h b/media/libvorbis/lib/misc.h
index 73b451989..13788445a 100644
--- a/media/libvorbis/lib/misc.h
+++ b/media/libvorbis/lib/misc.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: miscellaneous prototypes
- last mod: $Id: misc.h 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/floor_all.h b/media/libvorbis/lib/modes/floor_all.h
index 4292be326..20928aac8 100644
--- a/media/libvorbis/lib/modes/floor_all.h
+++ b/media/libvorbis/lib/modes/floor_all.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: key floor settings
- last mod: $Id: floor_all.h 17050 2010-03-26 01:34:42Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/psych_11.h b/media/libvorbis/lib/modes/psych_11.h
index 844a8ed3c..cc5eea240 100644
--- a/media/libvorbis/lib/modes/psych_11.h
+++ b/media/libvorbis/lib/modes/psych_11.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 11kHz settings
- last mod: $Id: psych_11.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/psych_16.h b/media/libvorbis/lib/modes/psych_16.h
index 1c10b3954..477cb4d90 100644
--- a/media/libvorbis/lib/modes/psych_16.h
+++ b/media/libvorbis/lib/modes/psych_16.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 16kHz settings
- last mod: $Id: psych_16.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/psych_44.h b/media/libvorbis/lib/modes/psych_44.h
index f05c03265..6c9eaa4e5 100644
--- a/media/libvorbis/lib/modes/psych_44.h
+++ b/media/libvorbis/lib/modes/psych_44.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: key psychoacoustic settings for 44.1/48kHz
- last mod: $Id: psych_44.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/psych_8.h b/media/libvorbis/lib/modes/psych_8.h
index 0e2dd5737..277db8436 100644
--- a/media/libvorbis/lib/modes/psych_8.h
+++ b/media/libvorbis/lib/modes/psych_8.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 8kHz psychoacoustic settings
- last mod: $Id: psych_8.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/residue_16.h b/media/libvorbis/lib/modes/residue_16.h
index dcaca5451..3e05471ce 100644
--- a/media/libvorbis/lib/modes/residue_16.h
+++ b/media/libvorbis/lib/modes/residue_16.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel residue templates 16/22kHz
- last mod: $Id: residue_16.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/residue_44.h b/media/libvorbis/lib/modes/residue_44.h
index 236c18341..e89bc0e48 100644
--- a/media/libvorbis/lib/modes/residue_44.h
+++ b/media/libvorbis/lib/modes/residue_44.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel residue templates for 32/44.1/48kHz
- last mod: $Id: residue_44.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/residue_44p51.h b/media/libvorbis/lib/modes/residue_44p51.h
index a52cc5245..7f33e250e 100644
--- a/media/libvorbis/lib/modes/residue_44p51.h
+++ b/media/libvorbis/lib/modes/residue_44p51.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel residue templates for 32/44.1/48kHz uncoupled
- last mod: $Id: residue_44p51.h 19013 2013-11-12 04:04:50Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/residue_44u.h b/media/libvorbis/lib/modes/residue_44u.h
index 92c4a09ce..e55ac1254 100644
--- a/media/libvorbis/lib/modes/residue_44u.h
+++ b/media/libvorbis/lib/modes/residue_44u.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel residue templates for 32/44.1/48kHz uncoupled
- last mod: $Id: residue_44u.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/residue_8.h b/media/libvorbis/lib/modes/residue_8.h
index 94c6d84c4..ae123a276 100644
--- a/media/libvorbis/lib/modes/residue_8.h
+++ b/media/libvorbis/lib/modes/residue_8.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel residue templates 8/11kHz
- last mod: $Id: residue_8.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_11.h b/media/libvorbis/lib/modes/setup_11.h
index 4c2d619ca..0cbcaafcb 100644
--- a/media/libvorbis/lib/modes/setup_11.h
+++ b/media/libvorbis/lib/modes/setup_11.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 11kHz settings
- last mod: $Id: setup_11.h 16894 2010-02-12 20:32:12Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_16.h b/media/libvorbis/lib/modes/setup_16.h
index 336007f98..d59ad70d2 100644
--- a/media/libvorbis/lib/modes/setup_16.h
+++ b/media/libvorbis/lib/modes/setup_16.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 16kHz settings
- last mod: $Id: setup_16.h 16894 2010-02-12 20:32:12Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_22.h b/media/libvorbis/lib/modes/setup_22.h
index 4fd5e5711..bc38af963 100644
--- a/media/libvorbis/lib/modes/setup_22.h
+++ b/media/libvorbis/lib/modes/setup_22.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 22kHz settings
- last mod: $Id: setup_22.h 17026 2010-03-25 05:00:27Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_32.h b/media/libvorbis/lib/modes/setup_32.h
index 2275ac961..f66a0bcd0 100644
--- a/media/libvorbis/lib/modes/setup_32.h
+++ b/media/libvorbis/lib/modes/setup_32.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel settings for 32kHz
- last mod: $Id: setup_32.h 16894 2010-02-12 20:32:12Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_44.h b/media/libvorbis/lib/modes/setup_44.h
index 3b88a89ac..a189b5fb9 100644
--- a/media/libvorbis/lib/modes/setup_44.h
+++ b/media/libvorbis/lib/modes/setup_44.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel settings for 44.1/48kHz
- last mod: $Id: setup_44.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_44p51.h b/media/libvorbis/lib/modes/setup_44p51.h
index 67d997960..3bde7b340 100644
--- a/media/libvorbis/lib/modes/setup_44p51.h
+++ b/media/libvorbis/lib/modes/setup_44p51.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel settings for 44.1/48kHz 5.1 surround modes
- last mod: $Id: setup_44p51.h 19013 2013-11-12 04:04:50Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_44u.h b/media/libvorbis/lib/modes/setup_44u.h
index 568b5f895..7ae3af6b2 100644
--- a/media/libvorbis/lib/modes/setup_44u.h
+++ b/media/libvorbis/lib/modes/setup_44u.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: toplevel settings for 44.1/48kHz uncoupled modes
- last mod: $Id: setup_44u.h 16962 2010-03-11 07:30:34Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_8.h b/media/libvorbis/lib/modes/setup_8.h
index 14c48374f..750255687 100644
--- a/media/libvorbis/lib/modes/setup_8.h
+++ b/media/libvorbis/lib/modes/setup_8.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: 8kHz settings
- last mod: $Id: setup_8.h 16894 2010-02-12 20:32:12Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/modes/setup_X.h b/media/libvorbis/lib/modes/setup_X.h
index a69f5d40a..2229a5ef2 100644
--- a/media/libvorbis/lib/modes/setup_X.h
+++ b/media/libvorbis/lib/modes/setup_X.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: catch-all toplevel settings for q modes only
- last mod: $Id: setup_X.h 16894 2010-02-12 20:32:12Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/os.h b/media/libvorbis/lib/os.h
index 8bc3e5fe9..416a401dd 100644
--- a/media/libvorbis/lib/os.h
+++ b/media/libvorbis/lib/os.h
@@ -13,7 +13,6 @@
  ********************************************************************
 
  function: #ifdef jail to whip a few platforms into the UNIX ideal.
- last mod: $Id: os.h 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -31,7 +30,7 @@
 
 #  ifdef __GNUC__
 #    define STIN static __inline__
-#  elif _WIN32
+#  elif defined(_WIN32)
 #    define STIN static __inline
 #  else
 #    define STIN static
diff --git a/media/libvorbis/lib/psy.h b/media/libvorbis/lib/psy.h
index c1ea82440..ab2534db3 100644
--- a/media/libvorbis/lib/psy.h
+++ b/media/libvorbis/lib/psy.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h 16946 2010-03-03 16:12:40Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/registry.h b/media/libvorbis/lib/registry.h
index 3ae04776d..599d95994 100644
--- a/media/libvorbis/lib/registry.h
+++ b/media/libvorbis/lib/registry.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: registry for time, floor, res backends and channel mappings
- last mod: $Id: registry.h 15531 2008-11-24 23:50:06Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/scales.h b/media/libvorbis/lib/scales.h
index 613f796e7..18bc4e751 100644
--- a/media/libvorbis/lib/scales.h
+++ b/media/libvorbis/lib/scales.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: linear scale -> dB, Bark and Mel scales
- last mod: $Id: scales.h 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/smallft.h b/media/libvorbis/lib/smallft.h
index 456497326..9e867c67d 100644
--- a/media/libvorbis/lib/smallft.h
+++ b/media/libvorbis/lib/smallft.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: fft transform
- last mod: $Id: smallft.h 13293 2007-07-24 00:09:47Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_analysis.c b/media/libvorbis/lib/vorbis_analysis.c
index 01aa6f30d..0e11a167b 100644
--- a/media/libvorbis/lib/vorbis_analysis.c
+++ b/media/libvorbis/lib/vorbis_analysis.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c 16226 2009-07-08 06:43:49Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_bitrate.c b/media/libvorbis/lib/vorbis_bitrate.c
index 3a71b1dc2..96055140f 100644
--- a/media/libvorbis/lib/vorbis_bitrate.c
+++ b/media/libvorbis/lib/vorbis_bitrate.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: bitrate tracking and management
- last mod: $Id: bitrate.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_block.c b/media/libvorbis/lib/vorbis_block.c
index 345c04276..db245b3e6 100644
--- a/media/libvorbis/lib/vorbis_block.c
+++ b/media/libvorbis/lib/vorbis_block.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c 19457 2015-03-03 00:15:29Z giles $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
diff --git a/media/libvorbis/lib/vorbis_codebook.c b/media/libvorbis/lib/vorbis_codebook.c
index 72f8a17a3..78672e222 100644
--- a/media/libvorbis/lib/vorbis_codebook.c
+++ b/media/libvorbis/lib/vorbis_codebook.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
@@ -387,7 +386,7 @@ long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
       t[i] = book->valuelist+entry[i]*book->dim;
     }
     for(i=0,o=0;i<book->dim;i++,o+=step)
-      for (j=0;j<step;j++)
+      for (j=0;o+j<n && j<step;j++)
         a[o+j]+=t[j][i];
   }
   return(0);
@@ -399,41 +398,12 @@ long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
     int i,j,entry;
     float *t;
 
-    if(book->dim>8){
-      for(i=0;i<n;){
-        entry = decode_packed_entry_number(book,b);
-        if(entry==-1)return(-1);
-        t     = book->valuelist+entry*book->dim;
-        for (j=0;j<book->dim;)
-          a[i++]+=t[j++];
-      }
-    }else{
-      for(i=0;i<n;){
-        entry = decode_packed_entry_number(book,b);
-        if(entry==-1)return(-1);
-        t     = book->valuelist+entry*book->dim;
-        j=0;
-        switch((int)book->dim){
-        case 8:
-          a[i++]+=t[j++];
-        case 7:
-          a[i++]+=t[j++];
-        case 6:
-          a[i++]+=t[j++];
-        case 5:
-          a[i++]+=t[j++];
-        case 4:
-          a[i++]+=t[j++];
-        case 3:
-          a[i++]+=t[j++];
-        case 2:
-          a[i++]+=t[j++];
-        case 1:
-          a[i++]+=t[j++];
-        case 0:
-          break;
-        }
-      }
+    for(i=0;i<n;){
+      entry = decode_packed_entry_number(book,b);
+      if(entry==-1)return(-1);
+      t     = book->valuelist+entry*book->dim;
+      for(j=0;i<n && j<book->dim;)
+        a[i++]+=t[j++];
     }
   }
   return(0);
@@ -471,12 +441,13 @@ long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
   long i,j,entry;
   int chptr=0;
   if(book->used_entries>0){
-    for(i=offset/ch;i<(offset+n)/ch;){
+    int m=(offset+n)/ch;
+    for(i=offset/ch;i<m;){
       entry = decode_packed_entry_number(book,b);
       if(entry==-1)return(-1);
       {
         const float *t = book->valuelist+entry*book->dim;
-        for (j=0;j<book->dim;j++){
+        for (j=0;i<m && j<book->dim;j++){
           a[chptr++][i]+=t[j];
           if(chptr==ch){
             chptr=0;
diff --git a/media/libvorbis/lib/vorbis_envelope.c b/media/libvorbis/lib/vorbis_envelope.c
index 010c66e2d..da7523754 100644
--- a/media/libvorbis/lib/vorbis_envelope.c
+++ b/media/libvorbis/lib/vorbis_envelope.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: PCM data envelope analysis
- last mod: $Id: envelope.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_floor0.c b/media/libvorbis/lib/vorbis_floor0.c
index 213cce4ec..443c0e5a9 100644
--- a/media/libvorbis/lib/vorbis_floor0.c
+++ b/media/libvorbis/lib/vorbis_floor0.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_floor1.c b/media/libvorbis/lib/vorbis_floor1.c
index d8bd4645c..673e954c5 100644
--- a/media/libvorbis/lib/vorbis_floor1.c
+++ b/media/libvorbis/lib/vorbis_floor1.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: floor backend 1 implementation
- last mod: $Id: floor1.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_info.c b/media/libvorbis/lib/vorbis_info.c
index 8a2a001f9..3fbb7c757 100644
--- a/media/libvorbis/lib/vorbis_info.c
+++ b/media/libvorbis/lib/vorbis_info.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -31,8 +30,8 @@
 #include "misc.h"
 #include "os.h"
 
-#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.3.5"
-#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20150105 (⛄⛄⛄⛄)"
+#define GENERAL_VENDOR_STRING "Xiph.Org libVorbis 1.3.6"
+#define ENCODE_VENDOR_STRING "Xiph.Org libVorbis I 20180316 (Now 100% fewer shells)"
 
 /* helpers */
 static void _v_writestring(oggpack_buffer *o,const char *s, int bytes){
@@ -65,11 +64,13 @@ void vorbis_comment_add(vorbis_comment *vc,const char *comment){
 }
 
 void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, const char *contents){
-  char *comment=alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
+  /* Length for key and value +2 for = and \0 */
+  char *comment=_ogg_malloc(strlen(tag)+strlen(contents)+2);
   strcpy(comment, tag);
   strcat(comment, "=");
   strcat(comment, contents);
   vorbis_comment_add(vc, comment);
+  _ogg_free(comment);
 }
 
 /* This is more or less the same as strncasecmp - but that doesn't exist
@@ -88,27 +89,30 @@ char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count){
   long i;
   int found = 0;
   int taglen = strlen(tag)+1; /* +1 for the = we append */
-  char *fulltag = alloca(taglen+ 1);
+  char *fulltag = _ogg_malloc(taglen+1);
 
   strcpy(fulltag, tag);
   strcat(fulltag, "=");
 
   for(i=0;i<vc->comments;i++){
     if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
-      if(count == found)
+      if(count == found) {
         /* We return a pointer to the data, not a copy */
-              return vc->user_comments[i] + taglen;
-      else
+        _ogg_free(fulltag);
+        return vc->user_comments[i] + taglen;
+      } else {
         found++;
+      }
     }
   }
+  _ogg_free(fulltag);
   return NULL; /* didn't find anything */
 }
 
 int vorbis_comment_query_count(vorbis_comment *vc, const char *tag){
   int i,count=0;
   int taglen = strlen(tag)+1; /* +1 for the = we append */
-  char *fulltag = alloca(taglen+1);
+  char *fulltag = _ogg_malloc(taglen+1);
   strcpy(fulltag,tag);
   strcat(fulltag, "=");
 
@@ -117,6 +121,7 @@ int vorbis_comment_query_count(vorbis_comment *vc, const char *tag){
       count++;
   }
 
+  _ogg_free(fulltag);
   return count;
 }
 
@@ -206,9 +211,9 @@ static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
   vi->channels=oggpack_read(opb,8);
   vi->rate=oggpack_read(opb,32);
 
-  vi->bitrate_upper=oggpack_read(opb,32);
-  vi->bitrate_nominal=oggpack_read(opb,32);
-  vi->bitrate_lower=oggpack_read(opb,32);
+  vi->bitrate_upper=(ogg_int32_t)oggpack_read(opb,32);
+  vi->bitrate_nominal=(ogg_int32_t)oggpack_read(opb,32);
+  vi->bitrate_lower=(ogg_int32_t)oggpack_read(opb,32);
 
   ci->blocksizes[0]=1<<oggpack_read(opb,4);
   ci->blocksizes[1]=1<<oggpack_read(opb,4);
@@ -583,7 +588,8 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
   oggpack_buffer opb;
   private_state *b=v->backend_state;
 
-  if(!b||vi->channels<=0){
+  if(!b||vi->channels<=0||vi->channels>256){
+    b = NULL;
     ret=OV_EFAULT;
     goto err_out;
   }
@@ -642,7 +648,7 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
   memset(op_code,0,sizeof(*op_code));
 
   if(b){
-    oggpack_writeclear(&opb);
+    if(vi->channels>0)oggpack_writeclear(&opb);
     if(b->header)_ogg_free(b->header);
     if(b->header1)_ogg_free(b->header1);
     if(b->header2)_ogg_free(b->header2);
diff --git a/media/libvorbis/lib/vorbis_lookup.c b/media/libvorbis/lib/vorbis_lookup.c
index 3321ed3db..1cc1f88ee 100644
--- a/media/libvorbis/lib/vorbis_lookup.c
+++ b/media/libvorbis/lib/vorbis_lookup.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: lookup based functions
-  last mod: $Id: lookup.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_lpc.c b/media/libvorbis/lib/vorbis_lpc.c
index f5199ec23..798f4cf07 100644
--- a/media/libvorbis/lib/vorbis_lpc.c
+++ b/media/libvorbis/lib/vorbis_lpc.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: LPC low level routines
-  last mod: $Id: lpc.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_lsp.c b/media/libvorbis/lib/vorbis_lsp.c
index bf5ab861c..77af0c66a 100644
--- a/media/libvorbis/lib/vorbis_lsp.c
+++ b/media/libvorbis/lib/vorbis_lsp.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
   function: LSP (also called LSF) conversion routines
-  last mod: $Id: lsp.c 19453 2015-03-02 22:35:34Z xiphmont $
 
   The LSP generation code is taken (with minimal modification and a
   few bugfixes) from "On the Computation of the LSP Frequencies" by
diff --git a/media/libvorbis/lib/vorbis_mapping0.c b/media/libvorbis/lib/vorbis_mapping0.c
index 85c7d22d8..ccb4493d4 100644
--- a/media/libvorbis/lib/vorbis_mapping0.c
+++ b/media/libvorbis/lib/vorbis_mapping0.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: channel mapping 0 implementation
- last mod: $Id: mapping0.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -93,7 +92,6 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
   int i,b;
   vorbis_info_mapping0 *info=_ogg_calloc(1,sizeof(*info));
   codec_setup_info     *ci=vi->codec_setup;
-  memset(info,0,sizeof(*info));
   if(vi->channels<=0)goto err_out;
 
   b=oggpack_read(opb,1);
diff --git a/media/libvorbis/lib/vorbis_mdct.c b/media/libvorbis/lib/vorbis_mdct.c
index 081633180..f3f1ed805 100644
--- a/media/libvorbis/lib/vorbis_mdct.c
+++ b/media/libvorbis/lib/vorbis_mdct.c
@@ -12,7 +12,6 @@
 
  function: normalized modified discrete cosine transform
            power of two length transform only [64 <= n ]
- last mod: $Id: mdct.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  Original algorithm adapted long ago from _The use of multirate filter
  banks for coding of high quality digital audio_, by T. Sporer,
diff --git a/media/libvorbis/lib/vorbis_psy.c b/media/libvorbis/lib/vorbis_psy.c
index f7a44c6d0..422c6f1e4 100644
--- a/media/libvorbis/lib/vorbis_psy.c
+++ b/media/libvorbis/lib/vorbis_psy.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c 18077 2011-09-02 02:49:00Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_registry.c b/media/libvorbis/lib/vorbis_registry.c
index 3961ed140..74f7ef039 100644
--- a/media/libvorbis/lib/vorbis_registry.c
+++ b/media/libvorbis/lib/vorbis_registry.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: registry for time, floor, res backends and channel mappings
- last mod: $Id: registry.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_res0.c b/media/libvorbis/lib/vorbis_res0.c
index ec11488c2..6d623d730 100644
--- a/media/libvorbis/lib/vorbis_res0.c
+++ b/media/libvorbis/lib/vorbis_res0.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: residue backend 0, 1 and 2 implementation
- last mod: $Id: res0.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_sharedbook.c b/media/libvorbis/lib/vorbis_sharedbook.c
index 6bfdf7311..4545d4f45 100644
--- a/media/libvorbis/lib/vorbis_sharedbook.c
+++ b/media/libvorbis/lib/vorbis_sharedbook.c
@@ -11,11 +11,11 @@
  ********************************************************************
 
  function: basic shared codebook operations
- last mod: $Id: sharedbook.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
 #include <stdlib.h>
+#include <limits.h>
 #include <math.h>
 #include <string.h>
 #include <ogg/ogg.h>
@@ -158,25 +158,34 @@ ogg_uint32_t *_make_words(char *l,long n,long sparsecount){
    that's portable and totally safe against roundoff, but I haven't
    thought of it.  Therefore, we opt on the side of caution */
 long _book_maptype1_quantvals(const static_codebook *b){
-  long vals=floor(pow((float)b->entries,1.f/b->dim));
+  long vals;
+  if(b->entries<1){
+    return(0);
+  }
+  vals=floor(pow((float)b->entries,1.f/b->dim));
 
   /* the above *should* be reliable, but we'll not assume that FP is
      ever reliable when bitstream sync is at stake; verify via integer
      means that vals really is the greatest value of dim for which
      vals^b->bim <= b->entries */
   /* treat the above as an initial guess */
+  if(vals<1){
+    vals=1;
+  }
   while(1){
     long acc=1;
     long acc1=1;
     int i;
     for(i=0;i<b->dim;i++){
+      if(b->entries/vals<acc)break;
       acc*=vals;
-      acc1*=vals+1;
+      if(LONG_MAX/(vals+1)<acc1)acc1=LONG_MAX;
+      else acc1*=vals+1;
     }
-    if(acc<=b->entries && acc1>b->entries){
+    if(i>=b->dim && acc<=b->entries && acc1>b->entries){
       return(vals);
     }else{
-      if(acc>b->entries){
+      if(i<b->dim || acc>b->entries){
         vals--;
       }else{
         vals++;
diff --git a/media/libvorbis/lib/vorbis_smallft.c b/media/libvorbis/lib/vorbis_smallft.c
index ae2bc41b6..6d528af42 100644
--- a/media/libvorbis/lib/vorbis_smallft.c
+++ b/media/libvorbis/lib/vorbis_smallft.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c 16227 2009-07-08 06:58:46Z xiphmont $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbis_synthesis.c b/media/libvorbis/lib/vorbis_synthesis.c
index 932d271a6..5f6092c3d 100644
--- a/media/libvorbis/lib/vorbis_synthesis.c
+++ b/media/libvorbis/lib/vorbis_synthesis.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: single-block PCM synthesis
- last mod: $Id: synthesis.c 19441 2015-01-21 01:17:41Z xiphmont $
 
  ********************************************************************/
 
@@ -117,7 +116,7 @@ int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
   if(!ci->mode_param[mode]){
     return(OV_EBADPACKET);
   }
-  
+
   vb->W=ci->mode_param[mode]->blockflag;
   if(vb->W){
     vb->lW=oggpack_read(opb,1);
diff --git a/media/libvorbis/lib/vorbis_window.c b/media/libvorbis/lib/vorbis_window.c
index 0305b7929..b3b7ce016 100644
--- a/media/libvorbis/lib/vorbis_window.c
+++ b/media/libvorbis/lib/vorbis_window.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.c 19028 2013-12-02 23:23:39Z tterribe $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/vorbisenc.c b/media/libvorbis/lib/vorbisenc.c
index b5d621e90..4a4607cb4 100644
--- a/media/libvorbis/lib/vorbisenc.c
+++ b/media/libvorbis/lib/vorbisenc.c
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: simple programmatic interface for encoder mode setup
- last mod: $Id: vorbisenc.c 19457 2015-03-03 00:15:29Z giles $
 
  ********************************************************************/
 
diff --git a/media/libvorbis/lib/window.h b/media/libvorbis/lib/window.h
index 51f97599f..6ac260749 100644
--- a/media/libvorbis/lib/window.h
+++ b/media/libvorbis/lib/window.h
@@ -11,7 +11,6 @@
  ********************************************************************
 
  function: window functions
- last mod: $Id: window.h 19028 2013-12-02 23:23:39Z tterribe $
 
  ********************************************************************/
 
