Error Creating RawDiskStream on a macbook pro running bootcamp
We've been using your library in our project https://github.com/rough007/CyLR and it's been great! But we do have a user who is experiencing some issues and we were hoping you might have some insight. Our tracking of the issue is here: https://github.com/rough007/CyLR/issues/50
The relevant part of the call stack we're getting is here: System.ArgumentOutOfRangeException: Non-negative number required. Parameter name: length at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) at System.Array.Copy(Array sourceArray, Int64 sourceIndex, Array destinationArray, Int64 destinationIndex, Int64 length) at RawDiskLib.RawDiskStream.Read(Byte[] buffer, Int32 offset, Int32 count)
I don't know if this issue is related to bootcamp or not, other users running bootcamp have been able to run the utility fine.
I should probably also mention that we're using a version of the library that is before you upgraded to .NET core.
Interesting. Have you got any details on what the parameters were? Were you f.ex. supplying a 0/negative count value?
It doesn't seem like it's reproducible for you (it seems a user of yours encountered it?), so testing could be cumbersome. If so, it'd be fun to know what the state was at crash time, like what was the position, the length of the disk, the input values to the Read call etc.
I think my initial response here would be to add more input validation to my calls, to catch any low hanging fruit.
As for other thoughts, it doesn't seem like an actual disk error.. Issues I've encountered in the past all related to how a disk can be read.. Typically there were bounds issues, especially around the ends of disks.
As a side note, you could use the version built and available on Nuget.
I'll look into switching over to the Nuget build, that'll be a lot more convenient. Yeah, I don't have a local repro, which makes this rather difficult to debug. I'll see if I can't find someone that can repro it in a dev environment to see if we can't get more info out of it.
If you encounter other issues with the library, when switching to Nuget, please do say so. I don't think anyone has really consumed the Nuget packages since I switched to Cores build environment :).
OK, I've dug into this a bit more and here's what I've got: We're using DiscUtils to read from the drive, (it rather serendipitously works great with RawDiskLib's RawDiskStream). This exception is happening when we're creating a new NtfsFileSystem instance.
NtfsFileSystem calls byte[] bytes = Utilities.ReadFully(stream, 512); which eventually ends up here:
public static int ReadFully(IBuffer buffer, long pos, byte[] data, int offset, int length)
{
int totalRead = 0;
int numRead = buffer.Read(pos, data, offset, length);
while (numRead > 0)
{
totalRead += numRead;
if (totalRead == length)
{
break;
}
numRead = buffer.Read(pos, data, offset + totalRead, length - totalRead);
}
return totalRead;
}
I think what's happening is that totalRead is at some point ending up greater than 512, meaning that we end up with a negative count in Read. Why that if check is an == and not a >= I couldn't really say, but I suspect that RawDisk's CreateDiskStream returns a stream that can occasionally return bad/unexpected lengths for its reads.
If you'd like we can try to add some debugging and see if @dnides can run a test for us. I've created a branch here, if you want to add some logging to the Read method, just push it there and I'll get it integrated with our project for testing.
Also, I pulled in the nuget libraries, and they work wonderfully. Thanks for making a great library!
Yes happy to help with any testing to isolate issue.
On Mon, Feb 27, 2017 at 9:28 PM, Jason Yegge [email protected] wrote:
If you'd like we can try to add some debugging and see if @dnides https://github.com/dnides can run a test for us. I've created a branch here https://github.com/Lansatac/RawDiskLib/tree/investigation/CyLR50, if you want to add some logging to the Read method, just push it there and I'll get it integrated with our project for testing.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/LordMike/RawDiskLib/issues/4#issuecomment-282931500, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2aZ0-16EMCPtzYJvODGQV_us3Wv8zSks5rg5RGgaJpZM4MI39q .
Well. Truly if the numRead is greater than length, it should be handled accordingly. I've never considered that situation before :O.
I unfortunately hit decline on the invitation, but you could insert a Debug.Assert() to check the condition. If it throws, then we know that at least that part is not so trustworthy :).
This code is from DiscUtils, right?
Funny coincidence. I also maintain a port of that to Dotnet Core :)