This project is read-only.

Getting "Cluster buffer too small" Exception in ReadClusters

Aug 26, 2014 at 2:24 PM
Please, if anyone have any ideas about this, I'd appreciate any guidance on this exception.
Thanks in advance.

I've seen previous thread that reported this same exception on WriteClusters, but, I'm getting it in the ReadClusters function.

I've attached StackTrace below... While running through my code, I get to ReadClusters function and eventually get's the exception.

In the following The logic checks for the buffer.Length (which in my case is 4096) and the count is '6' and _byterPerCluster = 4096, leading to the exception.

if (buffer.Length < (count * _bytesPerCluster) + offset)
        {
            throw new ArgumentException("Cluster buffer too small", "buffer");
        }
STACK TRACE:

8/26/2014 9:00:27 AM: System.ArgumentException: Cluster buffer too small
Parameter name: buffer
at DiscUtils.Ntfs.RawClusterStream.ReadClusters(Int64 startVcn, Int32 count, Byte[] buffer, Int32 offset) in c:\Users\kko\Documents\DiscUtilsSrc-f0bb9c34a81e-2014-May\discutils\src\Ntfs\RawClusterStream.cs:line 290
at DiscUtils.Ntfs.NonResidentDataBuffer.Read(Int64 pos, Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DiscUtilsSrc-f0bb9c34a81e-2014-May\discutils\src\Ntfs\NonResidentDataBuffer.cs:line 153
at DiscUtils.Ntfs.NtfsAttributeBuffer.Read(Int64 pos, Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DiscUtilsSrc-f0bb9c34a81e-2014-May\discutils\src\Ntfs\NtfsAttributeBuffer.cs:line 122
at DiscUtils.BufferStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DiscUtilsSrc-f0bb9c34a81e-2014-May\discutils\src\BufferStream.cs:line 119
at DiscUtils.Ntfs.File.FileStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DiscUtilsSrc-f0bb9c34a81e-2014-May\discutils\src\Ntfs\File.cs:line 1213
at DiscUtils.Ntfs.NtfsFileStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DiscUtilsSrc-f0bb9c34a81e-2014-May\discutils\src\Ntfs\NtfsFileStream.cs:line 143
at Smirk.Common.IndexDatParser.<GetVisits>d__0.MoveNext() in c:\Users\kko\Documents\SRC-SMIRK\Smirk\Smirk.Common\IndexDat.cs:line 197
Aug 26, 2014 at 6:15 PM
Hi,

This could be caused by passing in a buffer that is too small to NtfsFileStream.Read. I've just uploaded a change that adds extra checking on parameters - can you try that out, and see if it confirms the problem (or shows a new fault inside discutils).

Thanks!
Aug 26, 2014 at 6:48 PM
My code is reading an image file to parse data. This is a legitimate image file, so, I'm not sure why it's encountering this exception.
With the new changes you've made, I've got the following exception. If you have any ideas or suggestion what I need to do, I'd appreciate it.

8/26/2014 1:40:27 PM: System.ArgumentException: buffer is too small
Parameter name: buffer
at DiscUtils.Utilities.AssertBufferParameters(Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DIscUtilsSrc-f0bb9c34a81e-20May\discutils_1612cdaa985f\src\Utilities.cs:line 213
at DiscUtils.Ntfs.NtfsFileStream.Read(Byte[] buffer, Int32 offset, Int32 count) in c:\Users\kko\Documents\DIscUtilsSrc-f0bb9c34a81e-20May\discutils_1612cdaa985f\src\Ntfs\NtfsFileStream.cs:line 141
at Smirk.Common.IndexDatParser.<GetVisits>d__0.MoveNext() in c:\Users\kko\Documents\SRC-SMIRK\Smirk\Smirk.Common\IndexDat.cs:line 197
Aug 26, 2014 at 7:14 PM
This probably means there's a bug in your code.

Check the values you're passing in to NtfsFileStream.Read - it's likely the buffer is too small, or one (or both) of 'offset' or 'count' is too large. The 'buffer' parameter needs to be at least as big as 'offset' + 'count' bytes.


Ken
Aug 27, 2014 at 1:45 PM
You are right, I've found that there is a bug in our code.

Thank you for your assistance.