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

stdenv: Improve ELF detection for isELF #47244

Closed
wants to merge 1 commit into from

Conversation

aszlig
Copy link
Member

@aszlig aszlig commented Sep 23, 2018

The isELF function only checks whether ELF is contained within the first 4 bytes of the file, which is a bit fuzzy and will also return successful if it's a text file starting with ELF, for example:

ELF headers
-----------

Some text here about ELF headers...

So instead, we're now doing a precise match on \x7fELF.

@aszlig aszlig added the 6.topic: stdenv Standard environment label Sep 23, 2018
@@ -211,7 +211,7 @@ isELF() {
exec {fd}< "$fn"
read -r -n 4 -u "$fd" magic
exec {fd}<&-
if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi
if [ "$magic" = 'ELF' ]; then return 0; else return 1; fi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there is a 0x7F character here, GitHub just doesn't show it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'll probably change this to $'\177ELF.

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: stdenv

Partial log (click to expand)

cannot build derivation '/nix/store/hhvd335q7iffpnm4xjm00ng62sj40wl0-flex-2.6.4.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/qj1fx0375cwx4dn85gkxil780v9cjjaa-gnutar-1.30.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/vp8l8i6djxjf0daij5g549yll6y0kb7h-bootstrap_cmds-dev-tools-7.0.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/hlgbxkg525zwwga0b4l6wxy04qszzvic-cctools-binutils-darwin-wrapper.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/4573wy6il5j8gz3qws86b3xzjpbk2g7s-clang-wrapper-5.0.2.drv': 11 dependencies couldn't be built
cannot build derivation '/nix/store/1frapi1pwnxzbvnjb5qwdgyrdl7xxjz4-libkrb5-1.15.2.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/29grfk6a1v3mnrp0mgk4j49wzcsgm1va-curl-7.61.1.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/n3cvyd9hrk7w1b5ad7hqgvyg967zxysf-swift-corefoundation.drv': 8 dependencies couldn't be built
cannot build derivation '/nix/store/4gksj8f4wy3ihcsk34bfr9qf2ii2n4jc-stdenv-darwin.drv': 43 dependencies couldn't be built
error: build of '/nix/store/4gksj8f4wy3ihcsk34bfr9qf2ii2n4jc-stdenv-darwin.drv' failed

The isELF function only checks whether ELF is contained within the first
4 bytes of the file, which is a bit fuzzy and will also return
successful if it's a text file starting with ELF, for example:

  ELF headers
  -----------

  Some text here about ELF headers...

So instead, we're now doing a precise match on \x7fELF.

Signed-off-by: aszlig <aszlig@nix.build>
@GrahamcOfBorg
Copy link

Timed out, unknown build status on x86_64-linux (full log)

Attempted: stdenv

Partial log (click to expand)

cannot build derivation '/nix/store/rxzk5xn9z6kl0nb369k6viyvhgb8dmfk-help2man-1.47.6.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/8f197xd0g84qhnbshza7dk9h02sfyd9m-binutils-wrapper-2.30.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/cz6d7jr4jgcpls1fg8mgmhi4sbg8waz2-diffutils-3.6.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/i73sd4ffk6b0v6q4lq5vr5ngmnrmwaw1-findutils-4.6.0.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/7xi0rn6nx4ybqsmcb016m6hkx7vz3gss-libtool-2.4.6.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/piwbc2j1afcfij3jn8rxcd6g21fjzd5a-gcc-wrapper-7.3.0.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/8imjrs94n7vhxp02jjcjhgv4ma2ng97v-hook.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/0ggm5bnahhyb0y821gkzqi1dw54398sm-patch-2.7.6.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/hw89904n0k0ix1xhndngwymj745vz12f-stdenv-linux.drv': 23 dependencies couldn't be built
error: build of '/nix/store/hw89904n0k0ix1xhndngwymj745vz12f-stdenv-linux.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: stdenv

Partial log (click to expand)

cannot build derivation '/nix/store/xwzjpk6pik9msnadh9112v0wnhilkmdi-flex-2.6.4.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/9p1phra4yvqz6haj28wka2grhhy9r27p-gnutar-1.30.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/8268yqd9fsx7rjhwsvx2r1i12as03jrc-bootstrap_cmds-dev-tools-7.0.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/23jpv454vzvyajp8x5ywag6pnw0msdkg-cctools-binutils-darwin-wrapper.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/hxpr3d97ynxjkm9bbblgrblvr45jw408-clang-wrapper-5.0.2.drv': 11 dependencies couldn't be built
cannot build derivation '/nix/store/4hvna8a2zga7hi5db37mbs878a772r4g-libkrb5-1.15.2.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/300svd6041gha9z8x9gdq0wwfn8r7i2w-curl-7.61.1.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/0avgldfkwa5ffxac2w42fd43gngxbn6z-swift-corefoundation.drv': 8 dependencies couldn't be built
cannot build derivation '/nix/store/rp2kvcy30mp4rrszzrq2wh0z0d4565rj-stdenv-darwin.drv': 43 dependencies couldn't be built
error: build of '/nix/store/rp2kvcy30mp4rrszzrq2wh0z0d4565rj-stdenv-darwin.drv' failed

@dtzWill
Copy link
Member

dtzWill commented Sep 23, 2018

Is there something that motivated this? Just curious, especially since this and #47249 were submitted so close to each other.

@aszlig
Copy link
Member Author

aszlig commented Sep 23, 2018

@dtzWill: Yes, see #47222.

@GrahamcOfBorg
Copy link

Timed out, unknown build status on x86_64-linux (full log)

Attempted: stdenv

Partial log (click to expand)

cannot build derivation '/nix/store/3hqinlzcz5d4n10x8dhawa1f4fwhqamw-help2man-1.47.6.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/ilyrjs0r66w8z695j8f7xlf7hwwf265j-binutils-wrapper-2.30.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/mdkxl7g97ja1020q1xqv7nqm05xfz94i-diffutils-3.6.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/zn5dh93dki107vdf1b87w8568pz4cjx1-findutils-4.6.0.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/lb3ppajnhcjr3bxf0y3l91dqjwlb66i3-libtool-2.4.6.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/0rmaph4jvpp45fzjvgw3q6bxiq49yx2i-gcc-wrapper-7.3.0.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/np0ji3l22irw3j0d66sb07q4smzim88p-hook.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/309ynmllj9nmgn76jz5cf0mna3kzbzlm-patch-2.7.6.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/m3212880kwpvsk7p6spjxjk7m5asm688-stdenv-linux.drv': 23 dependencies couldn't be built
error: build of '/nix/store/m3212880kwpvsk7p6spjxjk7m5asm688-stdenv-linux.drv' failed

@GrahamcOfBorg
Copy link

Timed out, unknown build status on aarch64-linux (full log)

Attempted: stdenv

Partial log (click to expand)

cannot build derivation '/nix/store/xd5n57bxa6khir03va9ipzhfs7n1ncck-help2man-1.47.6.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/0fp35dlr22x4mz5jqv0cmvc4lkqirw5l-binutils-wrapper-2.30.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/wygm0zrn6sipr74q3lsyvr3zns2agwiz-diffutils-3.6.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/8x2jykagkwrd2gn8325v37cwaj4x051f-findutils-4.6.0.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/3cwq0b1cfsvnkp9mrqjwgids6idn0xh9-libtool-2.4.6.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/8mcwsnd6mxqsf8f7pjnkkpz78d31sfv4-gcc-wrapper-7.3.0.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/ps9xrb7x7g36rdkrg4qc4n06qskq2ai1-hook.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/0ywy02v8f14411kg930akhzlgsyf2cc6-patch-2.7.6.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/xwr8shlzib8lgm0mliilxcmigr3g17zs-stdenv-linux.drv': 25 dependencies couldn't be built
error: build of '/nix/store/xwr8shlzib8lgm0mliilxcmigr3g17zs-stdenv-linux.drv' failed

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

aszlig added a commit that referenced this pull request Sep 25, 2018
The isELF function only checks whether ELF is contained within the first
4 bytes of the file, which is a bit fuzzy and will also return
successful if it's a text file starting with ELF, for example:

  ELF headers
  -----------

  Some text here about ELF headers...

So instead, we're now doing a precise match on \x7fELF.

Signed-off-by: aszlig <aszlig@nix.build>
Acked-by: @Ericson2314
Closes: #47244
@aszlig aszlig closed this Sep 25, 2018
@aszlig aszlig deleted the better-iself branch September 25, 2018 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants