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

Array.indexOf() returns -1 for negative integers which exist in arrays of length >= 48 #27322

Open
idkidk000 opened this issue Dec 10, 2024 · 8 comments

Comments

@idkidk000
Copy link

Version: Deno 2.1.3

poc:

for (let value = -2; value < 2; value++) {
  for (let fill = -2; fill < 2; fill++) {
    if (value == fill) continue;
    for (let i = 0; i < 3; i++) {
      const length = 5 * Math.pow(10, i);
      const index = Math.floor(length / 2);
      const array = new Array(length).fill(fill);
      array[index] = value;
      const indexOf = array.indexOf(value);
      console.log({ value, fill, length, index, indexOf });
    }
  }
}

when run under node with:

docker run -it node node
.editor

[copy and paste poc code above]
[ctrl-d]
the index and indexOf always correctly match

when run under deno with:
docker run -it denoland/deno repl
[copy and paste poc code above]
indexOf is -1 when the array is of length>=50 and we're searching for an item whose value is a negative integer

find the array size at which the bug occurs:

for (let length = 5; length <= 50; length++) {
  const index = Math.floor(length / 2);
  const array = new Array(length).fill(0);
  array[index] = -1;
  const indexOf = array.indexOf(-1);
  console.log({ length, index, indexOf });
}

this works as expected under node but starts getting indexOf===-1 at length 48 in deno.

@dsherret
Copy link
Member

dsherret commented Dec 10, 2024

Is this on windows? (is the docker container windows as well?)

@idkidk000
Copy link
Author

tested locally on ubuntu and in docker. i don't have a windows machine available for testing.

@dsherret
Copy link
Member

How did you install Deno?

@idkidk000
Copy link
Author

using the installer curl -fsSL https://deno.land/install.sh | sh
but it's reproducible in the official deno docker container so it's not an install issue

@dsherret
Copy link
Member

Sorry, last question, are you on x86 or aarch64? It's strange because I've been able to see weird behaviour on Windows, but nowhere else.

@idkidk000
Copy link
Author

x86_64. a very old i5-3470 to be exact

@devsnek
Copy link
Member

devsnek commented Dec 10, 2024

This looks like a bug in V8, could you please report it here: https://issues.chromium.org/issues/wizard

@Seally
Copy link

Seally commented Dec 10, 2024

I went back through Deno official builds (Windows) and can confirm that this bug has existed since Deno v1.33.

I cannot reproduce on Deno v1.32.5 and earlier.

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

4 participants