Bugzilla – Bug 319926
file object.c: line 503 (compute_class_bitmap): assertion failed: ((field->offset % sizeof(gpointer)) == 0)
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by tjfontaine@gmail.com 2005-12-29 15:05:54 MST ---- Please fill in this template when reporting a bug, unless you know what you are doing. Description of Problem: Everytime code is run it aborts with: file object.c: line 503 (compute_class_bitmap): assertion failed: ((field->offset % sizeof(gpointer)) == 0) Steps to reproduce the problem: 1. Compile the following code with gmcs /unsafe Fat32.cs using System; using System.IO; using System.Runtime.InteropServices; namespace Atx.FileSystem.VFat { public class Fat32 { private ushort brsanity = 0x55AA; private uint fsisanity1 = 0x52526141; private uint fsisanity2 = 0x72724161; private Fat32BootRecord bootrecord; private Fat32FileSystemInfo filesysteminfo; private Stream file; public static void Main(string[] args) { Fat32 fat; if(File.Exists(args[0])) { using(FileStream fs = new FileStream(args[0], FileMode.Open)) { fat = new Fat32(fs); } } else { Console.WriteLine("Usage: Fat32.exe <fat32 image file>"); } } public Fat32(Stream f) { file = f; ReadBootRecord(); ReadFileSystemInfo(bootrecord.sectornumfsi, bootrecord.bytespersector); } private void ReadFileSystemInfo(int sectorNum, int sectorSize) { byte[] buff = new byte[512]; file.Seek(sectorNum * sectorSize, SeekOrigin.Begin); file.Read(buff, 0, 512); filesysteminfo = ReadStruct<Fat32FileSystemInfo>(buff); if (filesysteminfo.brsignature != brsanity || filesysteminfo.firstsignature != fsisanity1 || filesysteminfo.secondsignature != fsisanity2) throw new Exception("Failed File System Info Signature Sanity Check"); } private void ReadBootRecord() { byte[] buff = new byte[512]; file.Read(buff, 0, 512); bootrecord = ReadStruct<Fat32BootRecord>(buff); if (bootrecord.signature != brsanity) throw new Exception("Failed Boot Record Singature Sanity Check"); buff = null; } private T ReadStruct<T>(byte[] source) where T: struct { int objectSize = Marshal.SizeOf(typeof(T)); if (source.Length < objectSize) throw new Exception("Size Mismatch"); T returnStruct; unsafe { fixed (byte* bufferPointer = &source[0]) returnStruct = (T)Marshal.PtrToStructure((IntPtr)bufferPointer, typeof(T)); } return returnStruct; } } [StructLayout(LayoutKind.Sequential, Size=512, Pack = 1)] public struct Fat32FileSystemInfo { public uint firstsignature; [MarshalAs(UnmanagedType.ByValArray, SizeConst=480)] public byte[] unknown; public uint secondsignature; public uint numoffreeclusters; public uint recentclusteralloc; [MarshalAs(UnmanagedType.ByValArray, SizeConst=12)] public byte[] reserved; public ushort unknown2; public ushort brsignature; } [StructLayout(LayoutKind.Sequential, Size=512, Pack=1)] public struct Fat32BootRecord { [MarshalAs(UnmanagedType.ByValArray, SizeConst=3)] public byte[] jmpcode; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)] public string oemname; public ushort bytespersector; public byte sectorspercluster; public ushort reservedsectors; public byte numoffats; public ushort maxrootentries; public ushort numofsmallsectors; public byte mediadescriptor; public ushort sectorsperfat; public ushort sectorspertrack; public ushort numofheads; public uint numofhiddensectors; public uint numofsectors; public uint numofsectorsperfat; public ushort flags; public ushort version; public uint clusterstartnum; public ushort sectornumfsi; public ushort sectornumback; [MarshalAs(UnmanagedType.ByValArray, SizeConst=12)] public byte[] reserved; public byte logicaldrivenum; public byte unused; public byte extsignature; public uint serialnum; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=11)] public string volumename; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)] public string fatname; [MarshalAs(UnmanagedType.ByValArray, SizeConst=420)] public byte[] exectuablecode; public ushort signature; } } 2. run with mono Fat32.exe (with or without arguments) 3. Actual Results: tjfontaine@xenmaster:~$ mono Fat32.exe fat32.img ** ERROR **: file object.c: line 503 (compute_class_bitmap): assertion failed: ((field->offset % sizeof(gpointer)) == 0) aborting... Aborted Expected Results: it would run How often does this happen? every time Additional Information: The code compiles fine and runs as expected on ms.net 2.0. I tried several different ways to get around it, as it's own seperate assembly, generics and no unsafe, no generics with unsafe, and no generics and no unsafe, compiling with gmcs or mcs, with latest svn or 1.1.10 on multiple linux systems. All resulted in the same error. ---- Additional Comments From vargaz@gmail.com 2005-12-29 15:16:57 MST ---- Try removing the Pack=1 from the structures. *** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO76717 *** Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>ubuntu breezy</cf_op_sys_details> This bug was marked DUPLICATE in the database it was moved from. Changing resolution to "MOVED"