{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/1664","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/1664/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/1664/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/1664/events","html_url":"https://github.com/dotnet/corefx/issues/1664","id":74058877,"number":1664,"title":"System.Reflection.Metadata fails to read offset of DataDirectories spanning across multiple sections","user":{"login":"krwq","id":660048,"avatar_url":"https://avatars.githubusercontent.com/u/660048?v=3","gravatar_id":"","url":"https://api.github.com/users/krwq","html_url":"https://github.com/krwq","followers_url":"https://api.github.com/users/krwq/followers","following_url":"https://api.github.com/users/krwq/following{/other_user}","gists_url":"https://api.github.com/users/krwq/gists{/gist_id}","starred_url":"https://api.github.com/users/krwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krwq/subscriptions","organizations_url":"https://api.github.com/users/krwq/orgs","repos_url":"https://api.github.com/users/krwq/repos","events_url":"https://api.github.com/users/krwq/events{/privacy}","received_events_url":"https://api.github.com/users/krwq/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/corefx/labels/System.Reflection","name":"System.Reflection","color":"d4c5f9"}],"state":"open","locked":false,"assignee":{"login":"nguerrera","id":75470,"avatar_url":"https://avatars.githubusercontent.com/u/75470?v=3","gravatar_id":"","url":"https://api.github.com/users/nguerrera","html_url":"https://github.com/nguerrera","followers_url":"https://api.github.com/users/nguerrera/followers","following_url":"https://api.github.com/users/nguerrera/following{/other_user}","gists_url":"https://api.github.com/users/nguerrera/gists{/gist_id}","starred_url":"https://api.github.com/users/nguerrera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nguerrera/subscriptions","organizations_url":"https://api.github.com/users/nguerrera/orgs","repos_url":"https://api.github.com/users/nguerrera/repos","events_url":"https://api.github.com/users/nguerrera/events{/privacy}","received_events_url":"https://api.github.com/users/nguerrera/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-05-07T17:13:18Z","updated_at":"2015-05-07T21:13:59Z","closed_at":null,"body":"If an assembly contains any DataDirectory which is in more than one section we throw \"System.BadImageFormatException : Section too small.\". While I agree we should not have any assemblies like that we unfortunately already shipped one which has this issue.\r\n\r\nI believe we can still calculate the offset without checking ranges (or we can check the global range only)\r\n\r\nExample can be found here:\r\nhttps://github.com/krwq/corefx/tree/pereaderdatadir\r\n\r\nThis is basically:\r\n```csharp\r\nusing (FileStream fs = new FileStream(@\"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Microsoft.JScript.dll\", FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))\r\n{\r\n    using (PEReader reader = new PEReader(fs, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchEntireImage | PEStreamOptions.PrefetchMetadata))\r\n    {\r\n        int offset;\r\n        if (reader.PEHeaders.TryGetDirectoryOffset(reader.PEHeaders.PEHeader.CertificateTableDirectory, out offset))\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/100021095","html_url":"https://github.com/dotnet/corefx/issues/1664#issuecomment-100021095","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/1664","id":100021095,"user":{"login":"krwq","id":660048,"avatar_url":"https://avatars.githubusercontent.com/u/660048?v=3","gravatar_id":"","url":"https://api.github.com/users/krwq","html_url":"https://github.com/krwq","followers_url":"https://api.github.com/users/krwq/followers","following_url":"https://api.github.com/users/krwq/following{/other_user}","gists_url":"https://api.github.com/users/krwq/gists{/gist_id}","starred_url":"https://api.github.com/users/krwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krwq/subscriptions","organizations_url":"https://api.github.com/users/krwq/orgs","repos_url":"https://api.github.com/users/krwq/repos","events_url":"https://api.github.com/users/krwq/events{/privacy}","received_events_url":"https://api.github.com/users/krwq/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T21:13:59Z","updated_at":"2015-05-07T21:13:59Z","body":"I believe that removing this should fix this bug:\r\nhttps://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaders.cs#L307-L310"}}