Index: riff-media.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/riff/riff-media.c,v
retrieving revision 1.54
diff -u -r1.54 riff-media.c
--- riff-media.c	24 Feb 2006 16:21:34 -0000	1.54
+++ riff-media.c	5 Mar 2006 14:23:08 -0000
@@ -541,15 +541,17 @@
   }
 
   /* palette */
-  if (palette && GST_BUFFER_SIZE (palette) >= 256 * 4) {
-    GstBuffer *copy = gst_buffer_copy (palette);
+  if (palette && strf != NULL && GST_BUFFER_SIZE (palette) >= strf->num_colors * 4) {
+    /* the created palette is never smaller than 256 * 4 bytes */
+    GstBuffer *copy = gst_buffer_new_and_alloc (MAX(256 * 4, GST_BUFFER_SIZE (palette)));
+    memcpy(GST_BUFFER_DATA(copy), GST_BUFFER_DATA(palette), GST_BUFFER_SIZE (palette));
 
 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
     gint n;
     guint32 *data = (guint32 *) GST_BUFFER_DATA (copy);
 
     /* own endianness */
-    for (n = 0; n < 256; n++)
+    for (n = 0; n < strf->num_colors; n++)
       data[n] = GUINT32_FROM_LE (data[n]);
 #endif
     gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, copy, NULL);
