Revision: 53670
          http://brlcad.svn.sourceforge.net/brlcad/?rev=53670&view=rev
Author:   brlcad
Date:     2012-11-14 06:06:06 +0000 (Wed, 14 Nov 2012)
Log Message:
-----------
fixed one bug in the structparse table where it was reading a fastf_t as a char 
for the i_perspective field.  add some sanity checks to make sure we don't 
dereference into bad memory via the img_sp->i_img[] array.

Modified Paths:
--------------
    brlcad/trunk/src/liboptical/sh_prj.c

Modified: brlcad/trunk/src/liboptical/sh_prj.c
===================================================================
--- brlcad/trunk/src/liboptical/sh_prj.c        2012-11-14 06:03:39 UTC (rev 
53669)
+++ brlcad/trunk/src/liboptical/sh_prj.c        2012-11-14 06:06:06 UTC (rev 
53670)
@@ -381,7 +381,7 @@
     {"%c",     1, "through",           IMG_O(i_through),       
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
     {"%c",     1, "antialias",         IMG_O(i_antialias),     
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
     {"%c",     1, "behind",            IMG_O(i_behind),        
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
-    {"%c",     1, "perspective",       IMG_O(i_perspective),   persp_hook, 
NULL, NULL },
+    {"%f",     1, "perspective",       IMG_O(i_perspective),   persp_hook, 
NULL, NULL },
     {"",       0, (char *)0,           0,                      
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
 };
 struct bu_structparse img_print_tab[] = {
@@ -622,11 +622,34 @@
     if (rdebug&RDEBUG_SHADE) {
        VPRINT("sh_pt", sh_pt);
     }
+
+    /* make sure we have an image to project into */
+    if (img_sp->i_width <= 0 || img_sp->i_height <= 0) {
+       return 1;
+    }
+
     x = sh_pt[X] * (img_sp->i_width-1);
     y = sh_pt[Y] * (img_sp->i_height-1);
+
+    if (x<0 || y<0
+       || (x*3 + y*img_sp->i_width*3) < 0
+       || (x*3 + y*img_sp->i_width*3) > (img_sp->i_width * img_sp->i_height * 
3))
+    {
+       static int count=0;
+       static int suppressed=0;
+       if (count++ < 10) {
+           bu_log("INTERNAL ERROR: projection point is invalid\n");
+       } else {
+           if (!suppressed) {
+               suppressed++;
+               bu_log("INTERNAL ERROR: supressing further project point error 
messages\n");
+           }
+       }
+       return 1;
+    }
+
     pixel = &img_sp->i_img[x*3 + y*img_sp->i_width*3];
 
-
     if (x >= img_sp->i_width || x < 0 ||
        y >= img_sp->i_height || y < 0 ||
        ((img_sp->i_behind == '0' && sh_pt[Z] > 0.0))) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to