Open onlineque opened 1 year ago
Has the binary attribute been set on the file in your repo?
Either way, it wouldn't hurt for Salt to check for it rather than trying to guess.
I have tried with binary set in .gitattributes for the given file, but no luck, it's still the same. Zero length. I've marked all my .sh files as binary in .gitattributes this way:
*.sh binary
@onlineque would you mind submitting your fix as a PR alongside test coverage?
I'd be happy to do that ! :-)
Description I have a file, which is in fact a shell script with a binary blob attached to it. That blob begins at about 20KB, right after the script itself (which is a shell script, which means it is a text). When trying to run: salt '' cp.get_file salt://myfile /tmp/myfile
I am getting a file with zero length as the result in /tmp/myfile. I am using pygit2 as the fileserver backend.
Looks like the issue comes from salt/utils/gitfs.py here, line3054:
Seems in my case the file is wrongly guessed to be text, but in fact, it's not, causing this decode on line 3054 to fail on an exception., resulting in the destination file to be created with zero length and no data.
What I propose is to write that part in slightly different way:
so even wrong guess will not crash it, resulting in file being correctly transferred to destination.
Setup
Steps to Reproduce the behavior Create a text file which is of size more than 2048 bytes then append a binary one right after it. Such a way vendors are distributing installers for their products in a single file, which looks like a shell script, but contains the actual software bundled in the very same file. Then put it on the Salt fileserver which has its backend set to pygit2 and run: salt '' cp.get_file salt://myfile /tmp/myfile
You will receive file of a zero length with no content. Salt master log will be spammed with the following error:
Expected behavior I expect the file being transferred correctly under any circumstances.
Screenshots
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ```yaml Salt Version: Salt: 3005.1 Dependency Versions: cffi: 1.11.5 cherrypy: unknown dateutil: 2.6.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 2.10.1 libgit2: 0.26.8 M2Crypto: 0.35.2 Mako: Not Installed msgpack: 0.6.2 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.14 pycrypto: Not Installed pycryptodome: Not Installed pygit2: 0.26.4 Python: 3.6.8 (default, Nov 8 2022, 11:32:15) python-gnupg: Not Installed PyYAML: 3.12 PyZMQ: 20.0.0 smmap: Not Installed timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: rocky 8.7 Green Obsidian locale: UTF-8 machine: x86_64 release: 4.18.0-425.10.1.el8_7.x86_64 system: Linux version: Rocky Linux 8.7 Green Obsidian ```