LegacyNsfw / PcmHacks

PCM Hammer & PCM Logger, tools for General Motors Powertrain Control Modules (PCMs).
http://pcmhammer.org
171 stars 64 forks source link

Crash when trying to CRC segments of an invalid file #147

Closed antuspcm closed 3 years ago

antuspcm commented 4 years ago

If a P01 file is accidentally chosen for a flash in to a P59 computer, we get a crash at the local file CRC gathering stage. We might need to protect against that in the crc routine, or add a pre-flight check when doing a write that the file has the correct size before attempting to check CRCs. The error message also assumes the flash has begun, which it has not.

> [05:40:25:891]  Calculating CRCs from file...
> [05:40:25:964]  Something went wrong. Index was outside the bounds of the array.
> [05:40:25:970]  Do not power off the PCM! Do not exit this program!
> [05:40:25:976]  Try flashing again. If errors continue, seek help online.
> [05:40:25:982]  https://pcmhacking.net/forums/viewtopic.php?f=42&t=6080
> [05:40:25:988]  
> [05:40:25:999]  System.IndexOutOfRangeException: Index was outside the bounds of the array.
>    at PcmHacking.Crc.GetCrc(Byte[] buffer, UInt32 start, UInt32 length)
>    at PcmHacking.CKernelVerifier.GetCrcFromImage()
>    at PcmHacking.CKernelVerifier.<CompareRanges>d__7.MoveNext()
> --- End of stack trace from previous location where exception was thrown ---
>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
>    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
>    at PcmHacking.CKernelWriter.<Write>d__6.MoveNext()
> --- End of stack trace from previous location where exception was thrown ---
>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
>    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
>    at PcmHacking.CKernelWriter.<Write>d__5.MoveNext()
> [05:40:26:022]  Elapsed time 00:00:00.3340755
LegacyNsfw commented 3 years ago

Confirmed fixed:

[11:27:08:449] File size 524,288 does not match Flash Chip size 1,048,576!