microsoft / vscode-hexeditor

VS Code Hex Editor
https://marketplace.visualstudio.com/items?itemName=ms-vscode.hexeditor
MIT License
525 stars 85 forks source link

EACCES: permission denied on 444 file I own? #434

Closed coreyogburn closed 1 year ago

coreyogburn commented 1 year ago

I'm working on a file upload bit of go code for work. I have a binary file I'm uploading, validating, then saving to disk. While debugging things all on my local machine, I send my test file through the process and inspect the newly created output file. I click the file in VSCode's file browser, since it's a binary file I click "Open Anyway", vscode asks me which editor to open it with text vs hex and I click hex. I then get the following popup:

EACCES permission denied

This happens in VSCode v1.78.2 and VSCode Insiders v1.79.0-insider with Hex Editor v1.9.11 on Ubuntu 22.04 Jammy x86_64.

The file is owned by me, readable by everyone, can be read by command line tools as well as VSCode's text editor (with ugly binary results of course, but it works). For some reason the extension can't handle this file only after it passes through my API. The extension CAN successfully open and read the original file when it's in my Downloads folder that I upload from. If I completely close my API process, I still cannot open the uploaded file with the hex editor so I know I'm not leaving any file handles open. The code that processes the file is super simple: check the file extension and a few magic bytes at the beginning of the file then write the file to disk. The file on disk is a 100% match to the file I used to upload so I know my API isn't doing anything unusual in that regard. I can open other files on my system with the hex editor no problem. lsof lists no open handles on the file.

I see no reason why the hex editor shouldn't be able to access and read this file correctly. What's going on here?

Source code of the Go handler to show I'm not doing anything special:

Source Code ``` func postImport(w http.ResponseWriter, r *http.Request) { err := r.ParseMultipartForm(Config.MaxUploadSizeBytes) // a big number that doesn't get in the way if err != nil {...} file, header, err := r.FormFile("attachment") if err != nil {...} if file == nil {...} defer file.Close() if header.Size < 7 {...} magicBytes := make([]byte, 7) n, err := file.Read(magicBytes) if err != nil || n < 7 {...} // validate header.Filename and magicBytes, removed for brevity out, err := os.OpenFile(header.Filename, os.O_CREATE|os.O_WRONLY, 0444) if err != nil {...} defer out.Close() _, err = file.Seek(0, io.SeekStart) if err != nil {...} _, err = io.Copy(out, file) if err != nil {...} _ = r.MultipartForm.RemoveAll() } ``` Error handling has been removed for brevity. The handler returns a 200 and outputs the file to disk as expected. I've tested with a few PCAP and EVTX files and the same thing happens every time: the hex editor vscode extension gets permission denied when every other tool can read the files correctly.
connor4312 commented 1 year ago

Duplicates https://github.com/microsoft/vscode-hexeditor/issues/422

coreyogburn commented 1 year ago

Is it still a duplicate if running chmod 666 randpkt-2020-09-06-16170.pcap does not fix the error for me?