[Mono-bugs] [Bug 63809][Maj] New - Assembly.Load(byte) fails on repeated calls for same assembly - Possible FIX

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 24 Aug 2004 07:00:04 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by vasantha.paulraj@honeywell.com.

http://bugzilla.ximian.com/show_bug.cgi?id=63809

--- shadow/63809	2004-08-24 07:00:04.000000000 -0400
+++ shadow/63809.tmp.18526	2004-08-24 07:00:04.000000000 -0400
@@ -0,0 +1,135 @@
+Bug#: 63809
+Product: Mono: Runtime
+Version: unspecified
+OS: Red Hat 7.1
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: vasantha.paulraj@honeywell.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Assembly.Load(byte) fails on repeated calls for same assembly - Possible FIX
+
+Description of Problem:
+An attempt to load the same assembly twice using Assembly.Load(byte) leads 
+to an exception.
+ 
+Steps to reproduce the problem:
+Following is the sample code, that can be used to reproduce the problem
+/******************Code Starts Here**********************/
+ class Class1
+ {
+  static void Main(string[] args)
+  {
+ 
+   FileStream fs = File.OpenRead(@"C:\WorkArea\ClassLibrary1
+\bin\Debug\ClassLibrary1.dll");
+   BinaryReader br = new BinaryReader(fs);
+   byte[] assemblystream = br.ReadBytes((int)br.BaseStream.Length);
+   br.Close();
+   fs.Close();
+   
+   for(int i = 0; i<2; i++)
+   {
+    System.Reflection.Assembly assm = System.Reflection.Assembly.Load
+(assemblystream);
+    Console.WriteLine(assm.FullName);
+   }
+ 
+  }
+ }
+ 
+/******************Code Ends Here**********************/
+Actual Results:
+(gdb) bt
+#0  0x4022f0c7 in pthread_mutex_lock () from /lib/i686/libpthread.so.0
+#1  0x4207ac18 in free () from /lib/i686/libc.so.6
+#2  0x401d3e33 in g_free () from /usr/lib/libglib-2.0.so.0
+#3  0x400e2620 in mono_raw_buffer_free_malloc (base=0x818c744) at 
+rawbuffer.c:74
+#4  0x400d7ee5 in mono_image_close (image=0x814bbf8) at image.c:988
+#5  0x400d4219 in mono_assembly_load_from (image=0x814bbf8, 
+fname=0x4011bb79 "", status=0x40bca730) at assembly.c:743
+#6  0x400c8d92 in ves_icall_System_AppDomain_LoadAssemblyRaw 
+(ad=0x80dafc0, raw_assembly=0x815f000, raw_symbol_store=0x0, 
+evidence=0x80ddc78) at appdomain.c:899
+#7  0x402a690e in ?? ()
+#8  0x402a68ce in ?? ()
+#9  0x402a6840 in ?? ()
+#10 0x402a67e6 in ?? ()
+#11 0x402a65a3 in ?? ()
+#12 0x402a6551 in ?? ()
+#13 0x402a647e in ?? ()
+#14 0x402a051b in ?? ()
+#15 0x402a03f8 in ?? ()
+#16 0x4005fdf8 in mono_jit_runtime_invoke (method=0x8102730, obj=0x0, 
+params=0x40bca934, exc=0x0) at mini.c:8122
+#17 0x400a023b in mono_runtime_invoke (method=0x8102730, obj=0x0, 
+params=0x40bca934, exc=0x0) at object.c:998
+#18 0x400a0f81 in mono_runtime_exec_main (method=0x8102730, 
+args=0x806f8c0, exc=0x0) at object.c:1502
+#19 0x400a0b91 in mono_runtime_run_main (method=0x8102730, argc=0, 
+argv=0xbffff9cc, exc=0x0) at object.c:1356
+#20 0x400693bc in mono_jit_exec (domain=0x8070ed8, assembly=0x80fc878, 
+argc=1, argv=0xbffff9c8) at driver.c:468
+#21 0x4006945d in main_thread_handler (user_data=0xbffff920) at 
+driver.c:502
+#22 0x400c0af5 in start_wrapper (data=0x8102440) at threads.c:253
+#23 0x40102449 in timed_thread_start_routine (args=0x81020f0) at timed-
+thread.c:135
+#24 0x4011a260 in GC_start_routine (arg=0x806dca0) at 
+pthread_support.c:1184
+#25 0x4022dfef in pthread_start_thread () from /lib/i686/libpthread.so.0
+#26 0x4022e0df in pthread_start_thread_event () 
+from /lib/i686/libpthread.so.0
+(gdb) 
+ 
+Expected Results:
+ClassLibrary1, Version=1.0.1697.21845, Culture=neutral, PublicKeyToken=null
+ClassLibrary1, Version=1.0.1697.21845, Culture=neutral, PublicKeyToken=null
+ 
+How often does this happen? 
+Always
+ 
+Additional Information:
+Suggested Fix
+**************
+/******************Suggested Fix Starts Here**********************/
+--- image.c Tue Aug 24 14:40:50 2004
++++ mono-1.0/mono/metadata/image.c Tue Aug 24 15:07:10 2004
+@@ -960,8 +960,25 @@
+ 
+  if (image->f)
+   fclose (image->f);
+- if (image->raw_data_allocated)
++
++ /* possible fix - image->raw_metadata lies within the image->raw_data 
+and hence would always get 
++  * freed when the image->raw_data is freed.
++  */
++ if (image->raw_data_allocated) {
++  MonoCLIImageInfo *ii = image->image_info;
++  int i;
++  
++  if ((image->raw_metadata > image->raw_data) &&
++      (image->raw_metadata <= (image->raw_data + image->raw_data_len)))
++   image->raw_metadata = NULL;
++  
++  for (i = 0; i < ii->cli_section; i++)
++   if ((ii->cli_section[i] > image->raw_data) &&
++       (ii->cli_section[i] <= (image->raw_data + image->raw_data_len)))
++    ii->cli_section[i] = NULL;
++  
+   g_free (image->raw_data);
++ }
+ 
+  g_free (image->name);
+  g_free (image->files);
+ 
+/******************Suggested Fix Ends Here**********************/