[Bf-blender-cvs] [c0432c2385e] master: Fix T63046, T61413: crash reading paint slots from 32 bit .blend on 64 bit

Brecht Van Lommel noreply at git.blender.org
Mon May 6 18:54:38 CEST 2019


Commit: c0432c2385e655563cc9cfeec6e97f531d0b1f24
Author: Brecht Van Lommel
Date:   Mon May 6 18:02:22 2019 +0200
Branches: master
https://developer.blender.org/rBc0432c2385e655563cc9cfeec6e97f531d0b1f24

Fix T63046, T61413: crash reading paint slots from 32 bit .blend on 64 bit

Thanks to matc for helping to find this, it was writing the paint slots wrong.

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 78c5bdbed1d..ae4644f2950 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6624,6 +6624,13 @@ static void direct_link_paint(FileData *fd, const Scene *scene, Paint *p)
 
   p->tool_slots = newdataadr(fd, p->tool_slots);
 
+  /* Workaround for invalid data written in older versions. */
+  const size_t expected_size = sizeof(PaintToolSlot) * p->tool_slots_len;
+  if (p->tool_slots && MEM_allocN_len(p->tool_slots) < expected_size) {
+    MEM_freeN(p->tool_slots);
+    p->tool_slots = MEM_callocN(expected_size, "PaintToolSlot");
+  }
+
   BKE_paint_runtime_init(scene->toolsettings, p);
 }
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 9a4e2adc0e3..6305aa95e7f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2416,7 +2416,7 @@ static void write_paint(WriteData *wd, Paint *p)
   if (p->cavity_curve) {
     write_curvemapping(wd, p->cavity_curve);
   }
-  writedata(wd, DATA, sizeof(PaintToolSlot) * p->tool_slots_len, p->tool_slots);
+  writestruct(wd, DATA, PaintToolSlot, p->tool_slots_len, p->tool_slots);
 }
 
 static void write_layer_collections(WriteData *wd, ListBase *lb)



More information about the Bf-blender-cvs mailing list