gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/styles.cpp server/styles...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/styles.cpp server/styles...
Date: Thu, 04 Jan 2007 04:03:34 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/01/04 04:03:34

Modified files:
        .              : ChangeLog 
        server         : styles.cpp styles.h 
        server/parser  : shape_character_def.cpp 

Log message:
                * server/parser/shape_character_def.cpp (read):
                  use symbolic names for tags (not yet for flags: TODO);
                  (read_fill_styles): don't choke on malformed SWF.
                * server/styles.{h,cpp} (sample_gradient): made private,
                  changed arg type to be stricter, cleaned up;
                  (fill_style::read) don't choke on malformed SWF.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2044&r2=1.2045
http://cvs.savannah.gnu.org/viewcvs/gnash/server/styles.cpp?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/server/styles.h?cvsroot=gnash&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/shape_character_def.cpp?cvsroot=gnash&r1=1.8&r2=1.9

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2044
retrieving revision 1.2045
diff -u -b -r1.2044 -r1.2045
--- ChangeLog   4 Jan 2007 02:00:25 -0000       1.2044
+++ ChangeLog   4 Jan 2007 04:03:33 -0000       1.2045
@@ -1,7 +1,11 @@
 2007-01-04 Sandro Santilli <address@hidden>
 
        * server/parser/shape_character_def.cpp (read):
-         use symbolic names for tags (not yet for flags: TODO).
+         use symbolic names for tags (not yet for flags: TODO);
+         (read_fill_styles): don't choke on malformed SWF.
+       * server/styles.{h,cpp} (sample_gradient): made private,
+         changed arg type to be stricter, cleaned up;
+         (fill_style::read) don't choke on malformed SWF.
        * testsuite/actionscript.all/check.as: Ming can compile 'asm'
          blocks since 0.4.0.beta3, not beta2 (as of Ming's NEWS file).
 

Index: server/styles.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/styles.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- server/styles.cpp   29 Nov 2006 23:54:05 -0000      1.26
+++ server/styles.cpp   4 Jan 2007 04:03:33 -0000       1.27
@@ -113,13 +113,23 @@
         m_gradient_matrix.concatenate(m);
                                
         // GRADIENT
-        int    num_gradients = in->read_u8();
-        if (num_gradients < 1 || num_gradients > 8)
+        uint8_t num_gradients = in->read_u8();
+        if ( ! num_gradients )
+       {
+               IF_VERBOSE_MALFORMED_SWF(
+                       log_warning("Malformed SWF: num gradients 0");
+               );
+               return;
+       }
+
+        if ( num_gradients > 8 ) // SWF::DEFINESHAPE4 should support up to 15 !
+                                // and we don't have this limitation anyway
         {
             // see: http://sswf.sourceforge.net/SWFalexref.html#swf_gradient
             log_warning("Unexpected num gradients (%d), expected 1 to 8",
                     num_gradients);
         }                      
+
         m_gradients.resize(num_gradients);
         for (int i = 0; i < num_gradients; i++)        {
             m_gradients[i].read(in, tag_type);
@@ -194,7 +204,7 @@
         log_error("Unsupported fill style type: 0x%X", m_type);
         // This is a fatal error, we'll be leaving the stream
         // read pointer in an unknown position.
-        throw ParserException("Unsupported fill style");
+        throw ParserException("Unsupported fill style (Malformed SWF?)");
     }
 }
 
@@ -241,35 +251,63 @@
 }
 
 rgba
-fill_style::sample_gradient(int ratio) const
-    // Return the color at the specified ratio into our gradient.
-    // Ratio is in [0, 255].
+fill_style::sample_gradient(uint8_t ratio) const
 {
-    assert(ratio >= 0 && ratio <= 255);
     assert(m_type == SWF::FILL_LINEAR_GRADIENT
         || m_type == SWF::FILL_RADIAL_GRADIENT);
-    assert(m_gradients.size() > 0);
 
-    if (ratio < m_gradients[0].m_ratio) {
+       assert(m_gradients.size());
+
+       // By specs, first gradient should *always* be 0, 
+       // anyway a malformed SWF could break this we cannot rely on that 
information...
+       if (ratio < m_gradients[0].m_ratio)
+       {
+               IF_VERBOSE_MALFORMED_SWF(
+                       log_warning("MALFORMED SWF: "
+                               "First gradient in a fill_style "
+                               "have position==%d (expected 0)",
+                               m_gradients[0].m_ratio);
+               );
         return m_gradients[0].m_color;
     }
                 
+       if ( ratio >= m_gradients.back().m_ratio )
+       {
+               return m_gradients.back().m_color;
+       }
                
     for (size_t i = 1, n = m_gradients.size(); i < n; ++i)
     {
-        if (m_gradients[i].m_ratio >= ratio) {
-            const gradient_record& gr0 = m_gradients[i - 1];
             const gradient_record& gr1 = m_gradients[i];
+               if (gr1.m_ratio < ratio) continue;
+
+               const gradient_record& gr0 = m_gradients[i - 1];
+               if (gr0.m_ratio > ratio) continue;
+
             float      f = 0.0f;
-            if (gr0.m_ratio != gr1.m_ratio)    {
-                f = (ratio - gr0.m_ratio) / float(gr1.m_ratio - gr0.m_ratio);
+
+               if ( gr0.m_ratio != gr1.m_ratio )
+               {
+                       float f = (ratio - gr0.m_ratio) / float(gr1.m_ratio - 
gr0.m_ratio);
+               }
+               else
+               {
+                       // Ratios are equal IFF first and second gradient_record
+                       // have the same ratio. This would be a malformed SWF.
+                       IF_VERBOSE_MALFORMED_SWF(
+                               log_warning("MALFORMED SWF: "
+                                       "two gradients in a fill_style "
+                                       "have the same position/ratio: %d",
+                                       gr0.m_ratio);
+                       );
             }
 
             rgba       result;
-            result.set_lerp(m_gradients[i - 1].m_color, 
m_gradients[i].m_color, f);
+               result.set_lerp(gr0.m_color, gr1.m_color, f);
             return result;
         }
-    }
+
+       // Assuming gradients are ordered by m_ratio? see start comment
     return m_gradients.back().m_color;
 }
 

Index: server/styles.h
===================================================================
RCS file: /sources/gnash/gnash/server/styles.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- server/styles.h     11 Nov 2006 22:44:54 -0000      1.16
+++ server/styles.h     4 Jan 2007 04:03:33 -0000       1.17
@@ -5,7 +5,7 @@
 
 // Fill and line style types.
 
-/* $Id: styles.h,v 1.16 2006/11/11 22:44:54 strk Exp $ */
+/* $Id: styles.h,v 1.17 2007/01/04 04:03:33 strk Exp $ */
 
 #ifndef GNASH_STYLES_H
 #define GNASH_STYLES_H
@@ -46,10 +46,6 @@
        
        void    read(stream* in, int tag_type, movie_definition* m);
 
-    /// \brief
-    /// Return the color at the specified ratio into our gradient.
-    /// Ratio is in [0, 255].
-       rgba    sample_gradient(int ratio) const;
 
     /// \brief
     /// Make a bitmap_info* corresponding to our gradient.
@@ -95,6 +91,14 @@
        const gradient_record& get_color_stop(int index) const;
        
 private:
+
+       /// Return the color at the specified ratio into our gradient.
+       //
+       /// @param ratio
+       ///     Ratio is in the range [0, 255].
+       ///
+       rgba sample_gradient(uint8_t ratio) const;
+
        friend class morph2_character_def;
        friend class triangulating_render_handler;
        

Index: server/parser/shape_character_def.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/parser/shape_character_def.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- server/parser/shape_character_def.cpp       4 Jan 2007 02:00:25 -0000       
1.8
+++ server/parser/shape_character_def.cpp       4 Jan 2007 04:03:34 -0000       
1.9
@@ -6,7 +6,7 @@
 // Quadratic bezier outline shapes, the basis for most SWF rendering.
 
 
-/* $Id: shape_character_def.cpp,v 1.8 2007/01/04 02:00:25 strk Exp $ */
+/* $Id: shape_character_def.cpp,v 1.9 2007/01/04 04:03:34 strk Exp $ */
 
 #include "shape_character_def.h"
 
@@ -14,8 +14,8 @@
 #include "log.h"
 #include "render.h"
 #include "stream.h"
-//#include "bitmap_character_def.h"
 #include "sprite_instance.h"
+#include "GnashException.h"
 
 #include "tu_file.h"
 
@@ -54,11 +54,11 @@
 read_fill_styles(std::vector<fill_style>& styles, stream* in,
                int tag_type, movie_definition* m)
 {
-    //assert(styles);
 
     // Get the count.
-    int        fill_style_count = in->read_u8();
-    if (tag_type > 2) {
+       uint8_t fill_style_count = in->read_u8();
+       if (tag_type > 2)
+       {
        if (fill_style_count == 0xFF)
            {
                fill_style_count = in->read_u16();
@@ -66,15 +66,29 @@
     }
 
                IF_VERBOSE_PARSE (
-    log_parse("  read_fill_styles: count = %d", fill_style_count);
+               log_parse("  read_fill_styles: count = %ud", fill_style_count);
                );
 
     // Read the styles. 
-    for (int i = 0; i < fill_style_count; i++) {
-       styles.resize(styles.size() + 1);
-       //styles[styles.size() - 1].read(in, tag_type, m);
-       styles.back().read(in, tag_type, m);
+       styles.reserve(styles.size()+fill_style_count);
+       for (uint8_t i = 0; i < fill_style_count; ++i)
+       {
+               // TODO: add a fill_style constructor directly
+               //       reading from stream
+               fill_style fs;
+               try
+               {
+                       fs.read(in, tag_type, m); 
+                       styles.push_back(fs);
     }
+               catch (ParserException& e)
+               {
+                       IF_VERBOSE_MALFORMED_SWF(
+                               log_warning("%s", e.what());
+                       );
+               }
+       }
+
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]