corert icon indicating copy to clipboard operation
corert copied to clipboard

Add array bounds checks

Open morganbr opened this issue 7 years ago • 12 comments
trafficstars

Array accesses should throw an IndexOutOfRangeException (or trap) if the index is less than 0 or >= the array's length. #6383 established a similar pattern for null checks (calling a separate inlinable function that does the check to avoid having to juggle a bunch of basic blocks). The methods that need checks are:

  • ImportLoadElement
  • ImportStoreElement
  • ImportAddressOfElement

morganbr avatar Sep 30 '18 02:09 morganbr

Hi, I never contributed to an open source project before, but I would really like to contribute to the CoreRT project. This seems like an issue that I can pick up. Can I give it a try?

xatja avatar May 20 '20 11:05 xatja

You are welcomed to. cc @yowl

jkotas avatar May 20 '20 12:05 jkotas

A good place to look first could be

https://github.com/dotnet/corert/blob/325f31dce46e893506899c913c39be6c4b219750/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs#L4939-L4946

The NRE check is there.

yowl avatar May 20 '20 13:05 yowl

The coding style link seems broken, but I guess most of it is just common sense.

xatja avatar May 20 '20 14:05 xatja

Should be here now https://github.com/dotnet/runtime/blob/master/docs/coding-guidelines/coding-style.md

Suchiman avatar May 20 '20 14:05 Suchiman

Apologies if I'm being too pedantic, but llvm is not listed as a prerequisite for running a build on Ubuntu. It felt a bit useless to add an issue for that.

xatja avatar May 20 '20 18:05 xatja

Did step 4 at https://github.com/dotnet/corert/blob/master/Documentation/how-to-build-WebAssembly.md not work for you?

yowl avatar May 20 '20 19:05 yowl

Oh, no I meant the Prerequisites documentation. llvm is missing from the necessary apt packages in the Ubuntu section, however, I believe it is necessary to run the build.sh script.

xatja avatar May 20 '20 19:05 xatja

Hi yowl, I ran into some issues while running the WebAssembly build following the documentation.

  • The link for the Emscripten installation in the documentation redirects to a new page.
  • emcmake can not be found when using sudo, without sudo, running the build script results in a PermissionError, so you would need to change the ownership of the emscripten folder in the Emscripten-SDK.
  • libLLVMdep.depproj is no longer located in corert/tests/src/Simple/HelloWasm, I found a file with the same name in corert/src/ILCompiler.WebAssembly/src that worked for me.

My OS is Ubuntu 20.04, but the libLLVM.so for Ubuntu 18.04 works fine so far. There is no nuget packages yet for 20.04.

xatja avatar May 20 '20 21:05 xatja

Hi @yowl, I wanted to give a little update on running ILCompiler.WebAssembly on Ubuntu 20.04, I ran into libLLVM-9.so by accident while going through /usr/lib/, I think it comes with the default installation of the llvm apt package, however, it is versioned. Perhaps we could get around the tedious dotnet-restore procedure in step 4 of the wasm build documentation by setting an environment variable in the same we you do that for clang in the prerequisites documentation. Again, just trying to be of help. Apologies if I'm being very pedantic about the documentation.

xatja avatar May 21 '20 14:05 xatja

I'm not sure I understand what fails, the so file is used at runtime only so I would have thought that as long as there is the sym link in /usr/lib the normal linux library resolving should find it. We could add a step to the documentation, /sbin/ldconfig -v -N | grep libLLVM and check for a v9 ?

yowl avatar May 21 '20 16:05 yowl

The other option that Jan mentioned is to try the CentOS version and see if we can get away with that being as its a fairly "vanilla" linux distro. If that works we can create a PR in LLVMSharp to create a nuget based on that binary, but with the generic RID,linux-x64

yowl avatar May 21 '20 16:05 yowl