Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadHGlobalIntoStream has an issue with files over 4096 bytes. #48

Open
MWiz3 opened this issue May 25, 2023 · 0 comments
Open

ReadHGlobalIntoStream has an issue with files over 4096 bytes. #48

MWiz3 opened this issue May 25, 2023 · 0 comments

Comments

@MWiz3
Copy link

MWiz3 commented May 25, 2023

Testing the ReadHGlobalIntoStream method I found my result had corrupted files if their size was over 4096 bytes.

I believe adding this line corrected the issue:

source = new IntPtr(source.ToInt64() + bytesToCopy);

So that the loop looks like:

int bytesToCopy;
for (int offset = 0; offset < length; offset += buffer.Length)
{
            //Copy buffer length or remaining length, whichever is smaller
            bytesToCopy = Math.Min(buffer.Length, length - offset);
            Marshal.Copy(source, buffer, 0, bytesToCopy);
            stream.Write(buffer, 0, bytesToCopy);
            source = new IntPtr(source.ToInt64() + bytesToCopy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant