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

BitArray.CopyTo(Array, int) seems broken #30440

Closed
MichaelL79 opened this issue Jul 30, 2019 · 5 comments
Closed

BitArray.CopyTo(Array, int) seems broken #30440

MichaelL79 opened this issue Jul 30, 2019 · 5 comments
Assignees
Milestone

Comments

@MichaelL79
Copy link

BitArray.CopyTo(Array, int) seems broken

When using BitArray.CopyTo() in .NET Core 3 it seems the bits are always copied to the last position of the provided array.

General

My setup is a .NetStandard 2 class library with a method that contains a BitArray.CopyTo(Array, int). If I use this library from within a WPF application using .Net 4.7.2 everything works as expected. When I use the exact same library from within a .NET Core 3 application (Console or WPF) always the last byte of the array is overwritten and the index parameter is ignored. Example:

bool[] directionBools = { true, true, true, true };
bool[] levelBools = { false, false, false, true };
byte[] byteHolder = new byte[2];
BitArray directionBits = new BitArray(directionBools);
BitArray levelBits = new BitArray(levelBools);

directionBits.CopyTo(byteHolder, 0);
levelBits.CopyTo(byteHolder, 1);

In .NET 4.7.2 and earlier this would result in an array 0F-08. In .NET Core 3 it results in an array 00-08 as the second CopyTo overwrites the 0F that was wrongly copied to index 1 instead of index 0. If you increase the byteHolder length to eg. 5. It would result in 0F-08-00-00-00 in 4.7.2 and 00-00-00-00-08 in Core 3.

Best regards
Michael

@carlossanlop
Copy link
Member

Hello @MichaelL79 , thanks for reporting this.
Since this is a potential issue in our libraries, I will transfer it to the dotnet/corefx repo for higher visibility.

@carlossanlop carlossanlop transferred this issue from dotnet/core Jul 31, 2019
@Clockwork-Muse
Copy link
Contributor

Behavior confirmed....

But we have a test to protect against this, that passes!? (Verified under debug of test)..... what?

I know there also used to be a copy distributed along with coreclr, although that's long gone.

@jkotas
Copy link
Member

jkotas commented Aug 1, 2019

Regression introduced by @ahsonkhan 's change dotnet/corefx#33367

@ahsonkhan ahsonkhan self-assigned this Aug 15, 2019
@ericstj
Copy link
Member

ericstj commented Aug 19, 2019

@ahsonkhan can you provide an update here? Will a fix make it in for Preview9?

@ahsonkhan
Copy link
Member

ahsonkhan commented Aug 21, 2019

Fixed in dotnet/corefx#40442 for release/3.0 (for preview 9 and above) and in dotnet/corefx#40441 for master.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants