Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix remote code execution vulnerability in the PDF OCR converter (#110)
ENG-3252
- Loading branch information
1 parent
44d6739
commit b19021a
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //go:build ocr | ||
| // +build ocr | ||
|
|
||
| package docconv | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestPDFHasImage_CannotExecuteCode(t *testing.T) { | ||
| // Try to inject code by passing a bad file path. | ||
| // If the code was successful it will create a file called foo in the working directory | ||
| badFilePath := "$(id >> foo).pdf" | ||
| if got, want := PDFHasImage(badFilePath), false; got != want { | ||
| t.Errorf("got %v, want %v", got, want) | ||
| } | ||
|
|
||
| if got, want := fileExists("foo"), false; got != want { | ||
| t.Errorf("got bad file exists, want not file to exist") | ||
| } | ||
| } | ||
|
|
||
| func fileExists(filename string) bool { | ||
| info, err := os.Stat(filename) | ||
| if os.IsNotExist(err) { | ||
| return false | ||
| } | ||
| return !info.IsDir() | ||
| } |