azure-dev icon indicating copy to clipboard operation
azure-dev copied to clipboard

macOS bash installer installs corrupt binary

Open tonybaloney opened this issue 3 years ago • 1 comments

Trying to install azd on macOS 12.5 on an Intel Mac.

The installer downloads a corrupt binary that cannot start:

> bash install-azd.sh --verbose
install-azd: Version: latest
install-azd: Platform: darwin
install-azd: Architecture: amd64
install-azd: File extension: zip
install-azd: Downloading https://azure-dev.azureedge.net/azd/standalone/release/latest/azd-darwin-amd64.zip to /var/folders/j4/zngd8xzn5bj14jfr2vyygwj40000gn/T/tmp.HAcVI7VS
Archive:  /var/folders/j4/zngd8xzn5bj14jfr2vyygwj40000gn/T/tmp.HAcVI7VS/azd-darwin-amd64.zip
  inflating: /var/folders/j4/zngd8xzn5bj14jfr2vyygwj40000gn/T/tmp.HAcVI7VS/azd-darwin-amd64  
install-azd: Cleaning up temp folder: /var/folders/j4/zngd8xzn5bj14jfr2vyygwj40000gn/T/tmp.HAcVI7VS
install-azd: Successfully installed to /usr/local/bin/azd
> azd
zsh: killed     azd

I tried running this through lldb as well. The binary is corrupted.

> lldb /usr/local/bin/azd 
Added Microsoft public symbol server
(lldb) target create "/usr/local/bin/azd"
Current executable set to '/usr/local/bin/azd' (x86_64).
(lldb) run
error: Bad executable (or shared library)
(lldb) exit

tonybaloney avatar Aug 04 '22 23:08 tonybaloney

I've installed it twice. Same issue

CC @jongio

tonybaloney avatar Aug 04 '22 23:08 tonybaloney

@danieljurek when you get a chance. can you try this?

rajeshkamal5050 avatar Aug 30 '22 04:08 rajeshkamal5050

Thanks for the report @tonybaloney -- I've started looking into this. I'm able to reproduce behavior like this by installing different versions on top of an existing azd installation. That is, installing latest and immediately installing daily results in a similar error. Investigation ongoing.

danieljurek avatar Aug 30 '22 15:08 danieljurek

Further investigation into this reveals that the OS caches signatures for binaries (source).

macOS caches information about the code’s signature in the kernel. It doesn’t flush that cache when you modify the file’s contents. Modifying the file in place yields a mismatch between the file’s contents and the in-kernel cache, which can cause a hard-to-reproduce code-signing crash the next time you run the tool.

There are two fixes here:

  • Use mv instead of cp to overwrite the installed binary
  • Restart the computer

I'm working on a fix that uses mv in #554

danieljurek avatar Aug 30 '22 18:08 danieljurek