AddImport ArgumentOutOfRangeException Regression (v2.4.1+)
SapientGuardian opened this issue · 4 comments
Hello,
Version 2.4.1 of this library made a change to AddImports ( v2.4.0...v2.4.1#diff-acaaea654416d997f1e18c07aeeb102b4934dcfda5ff6e66b5852479f5c20f08 ) which causes an ArgumentOutOfRangeException to be thrown on some inputs.
Message:
System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. (Parameter 'length')
Stack Trace:
BufferFile.WriteULong(Int64 offset, UInt64 value) line 51
ImageThunkData.set_AddressOfData(UInt64 value) line 37
PeFile.<AddImports>g__AddThunkDatas|1_4(UInt32& offset, List`1 adrList, <>c__DisplayClass1_0& ) line 106
PeFile.<AddImports>g__AddImportWithNewImpDesc|1_5(UInt32& tmpOffset, Int64& paIdesc, AdditionalImport ai, <>c__DisplayClass1_0& ) line 129
PeFile.AddImports(List`1 additionalImports) line 148
ImportTest.AddImport_Regression() line 71
I have added a regression test demonstrating this issue here:
https://github.com/SapientGuardian/PeNet/tree/AddImportRegression
Please let me know if you'd like me to submit a pull request with the failing test.
Based on the exception and the diff, I believe this input is causing PeNet to underestimate the size of the new import section where it did not previously.
Hi @SapientGuardian,
thanks for reporting the regression. A PR with a failing test very welcome! It helps me a lot to fix the issue, so please create one. I'll have a look at it asap and release a fix.
Submitted #195 . Thanks for the quick response, and for creating this library!
I hopefully fixed it finally. A new version 2.6.3 should be available in the next minutes, as soon as nuget.org indexed it. I'll keep the issue open until you had time to verify that it works as expected.
Confirmed, 2.6.3 does not have the issue, and the resulting executable consumed the import successfully. Thanks for the quick fix!