[Spice-commits] 2 commits - server/red_common.h server/red_parse_qxl.c server/red_worker.c

Alon Levy alon at kemper.freedesktop.org
Sun Jul 22 03:03:28 PDT 2012


 server/red_common.h    |   12 ++++++++++++
 server/red_parse_qxl.c |    9 +++++++++
 server/red_worker.c    |   19 +++++++++++--------
 3 files changed, 32 insertions(+), 8 deletions(-)

New commits:
commit b8ccb7da652dd33ee7fa2552ee753759def6c641
Author: Alon Levy <alevy at redhat.com>
Date:   Thu Jul 12 20:45:57 2012 +0300

    server: don't abort on guest images with missing palettes

diff --git a/server/red_parse_qxl.c b/server/red_parse_qxl.c
index e6c2705..daae897 100644
--- a/server/red_parse_qxl.c
+++ b/server/red_parse_qxl.c
@@ -328,6 +328,10 @@ static SpiceChunks *red_get_image_data_chunked(RedMemSlotInfo *slots, int group_
     return data;
 }
 
+// This is based on SPICE_BITMAP_FMT_*, copied from server/red_worker.c
+// to avoid a possible unoptimization from making it non static.
+static const int BITMAP_FMT_IS_RGB[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1};
+
 static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id,
                                  QXLPHYSICAL addr, uint32_t flags)
 {
@@ -362,6 +366,11 @@ static SpiceImage *red_get_image(RedMemSlotInfo *slots, int group_id,
     switch (red->descriptor.type) {
     case SPICE_IMAGE_TYPE_BITMAP:
         red->u.bitmap.format = qxl->bitmap.format;
+        if (!bitmap_fmt_is_rgb(qxl->bitmap.format) && !qxl->bitmap.palette) {
+            spice_warning("guest error: missing palette on bitmap format=%d\n",
+                          red->u.bitmap.format);
+            return NULL;
+        }
         qxl_flags = qxl->bitmap.flags;
         if (qxl_flags & QXL_BITMAP_TOP_DOWN) {
             red->u.bitmap.flags = SPICE_BITMAP_FLAGS_TOP_DOWN;
diff --git a/server/red_worker.c b/server/red_worker.c
index 71df5a1..5634db5 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -6014,6 +6014,10 @@ static inline int red_lz_compress_image(DisplayChannelClient *dcc,
         o_comp_data->comp_buf = lz_data->data.bufs_head;
         o_comp_data->comp_buf_size = size;
     } else {
+        if (!src->palette) {
+            spice_warning("bad guest: missing palette\n");
+            return FALSE;
+        }
         dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_PLT;
         dest->u.lz_plt.data_size = size;
         dest->u.lz_plt.flags = src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN;
commit d4780374041e6bb6322e23725bf7937aaa2238b7
Author: Alon Levy <alevy at redhat.com>
Date:   Mon Jul 16 11:36:44 2012 +0300

    server: factor out bitmap_fmt_is_rgb

diff --git a/server/red_common.h b/server/red_common.h
index cb7bf71..b52a7d1 100644
--- a/server/red_common.h
+++ b/server/red_common.h
@@ -35,4 +35,16 @@ enum {
     STREAM_VIDEO_FILTER
 };
 
+static inline int bitmap_fmt_is_rgb(uint8_t fmt)
+{
+    static const int BITMAP_FMT_IS_RGB[SPICE_BITMAP_FMT_ENUM_END] =
+                                        {0, 0, 0, 0, 0, 0, 1, 1, 1, 1};
+
+    if (fmt >= SPICE_BITMAP_FMT_ENUM_END) {
+        spice_warning("fmt >= SPICE_BITMAP_FMT_ENUM_END");
+        return 0;
+    }
+    return BITMAP_FMT_IS_RGB[fmt];
+}
+
 #endif
diff --git a/server/red_worker.c b/server/red_worker.c
index ac9baf2..71df5a1 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -431,7 +431,6 @@ struct RedCompressBuf {
 };
 
 static const int BITMAP_FMT_IS_PLT[] = {0, 1, 1, 1, 1, 1, 0, 0, 0, 0};
-static const int BITMAP_FMT_IS_RGB[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1};
 static const int BITMAP_FMP_BYTES_PER_PIXEL[] = {0, 0, 0, 0, 0, 1, 2, 3, 4, 4};
 
 pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -3073,7 +3072,7 @@ static inline void red_update_copy_graduality(RedWorker* worker, Drawable *drawa
 
     bitmap = &drawable->red_drawable->u.copy.src_bitmap->u.bitmap;
 
-    if (!BITMAP_FMT_IS_RGB[bitmap->format] || _stride_is_extra(bitmap) ||
+    if (!bitmap_fmt_is_rgb(bitmap->format) || _stride_is_extra(bitmap) ||
         (bitmap->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE)) {
         drawable->copy_bitmap_graduality = BITMAP_GRADUAL_NOT_AVAIL;
     } else  {
@@ -5811,7 +5810,7 @@ static BitmapGradualType _get_bitmap_graduality_level(RedWorker *worker, SpiceBi
 static inline int _stride_is_extra(SpiceBitmap *bitmap)
 {
     spice_assert(bitmap);
-    if (BITMAP_FMT_IS_RGB[bitmap->format]) {
+    if (bitmap_fmt_is_rgb(bitmap->format)) {
         return ((bitmap->x * BITMAP_FMP_BYTES_PER_PIXEL[bitmap->format]) < bitmap->stride);
     } else {
         switch (bitmap->format) {
@@ -5865,7 +5864,7 @@ static inline int red_glz_compress_image(DisplayChannelClient *dcc,
 #ifdef COMPRESS_STAT
     stat_time_t start_time = stat_now();
 #endif
-    spice_assert(BITMAP_FMT_IS_RGB[src->format]);
+    spice_assert(bitmap_fmt_is_rgb(src->format));
     GlzData *glz_data = &dcc->glz_data;
     ZlibData *zlib_data;
     LzImageType type = MAP_BITMAP_FMT_TO_LZ_IMAGE_TYPE[src->format];
@@ -6008,7 +6007,7 @@ static inline int red_lz_compress_image(DisplayChannelClient *dcc,
         longjmp(lz_data->data.jmp_env, 1);
     }
 
-    if (BITMAP_FMT_IS_RGB[src->format]) {
+    if (bitmap_fmt_is_rgb(src->format)) {
         dest->descriptor.type = SPICE_IMAGE_TYPE_LZ_RGB;
         dest->u.lz_rgb.data_size = size;
 
@@ -6303,7 +6302,7 @@ static inline int red_compress_image(DisplayChannelClient *dcc,
                     quic_compress = FALSE;
                 } else {
                     if (drawable->copy_bitmap_graduality == BITMAP_GRADUAL_INVALID) {
-                        quic_compress = BITMAP_FMT_IS_RGB[src->format] &&
+                        quic_compress = bitmap_fmt_is_rgb(src->format) &&
                             (_get_bitmap_graduality_level(display_channel->common.worker, src,
                                                           drawable->group_id) ==
                              BITMAP_GRADUAL_HIGH);
@@ -6338,7 +6337,7 @@ static inline int red_compress_image(DisplayChannelClient *dcc,
         int ret;
         if ((image_compression == SPICE_IMAGE_COMPRESS_AUTO_GLZ) ||
             (image_compression == SPICE_IMAGE_COMPRESS_GLZ)) {
-            glz = BITMAP_FMT_IS_RGB[src->format] && (
+            glz = bitmap_fmt_is_rgb(src->format) && (
                     (src->x * src->y) < glz_enc_dictionary_get_size(
                         dcc->glz_dict->dict));
         } else if ((image_compression == SPICE_IMAGE_COMPRESS_AUTO_LZ) ||
@@ -8411,7 +8410,7 @@ static void red_marshall_image(RedChannelClient *rcc, SpiceMarshaller *m, ImageI
 
     if ((comp_mode == SPICE_IMAGE_COMPRESS_AUTO_LZ) ||
         (comp_mode == SPICE_IMAGE_COMPRESS_AUTO_GLZ)) {
-        if (BITMAP_FMT_IS_RGB[item->image_format]) {
+        if (bitmap_fmt_is_rgb(item->image_format)) {
             if (!_stride_is_extra(&bitmap)) {
                 BitmapGradualType grad_level;
                 grad_level = _get_bitmap_graduality_level(display_channel->common.worker,


More information about the Spice-commits mailing list