fix bug in output filename calculation in plot_radial_build.py#3008
Merged
timothy-nunn merged 1 commit intoukaea:mainfrom Dec 20, 2023
Merged
fix bug in output filename calculation in plot_radial_build.py#3008timothy-nunn merged 1 commit intoukaea:mainfrom
timothy-nunn merged 1 commit intoukaea:mainfrom
Conversation
timothy-nunn
requested changes
Dec 7, 2023
Collaborator
timothy-nunn
left a comment
There was a problem hiding this comment.
Hi @alekitto,
Thank you for your contribution to the PROCESS repository by identifying and proposing a fix to this bug.
I think pathlib may offer a nicer, more modern fix to this bug, and have suggested as such.
Collaborator
There was a problem hiding this comment.
Suggested change
| f"{args.outputdir}/{os.path.splitext(os.path.basename(args.input))[0]}_radial_build.{save_format}", | |
| f"{args.outputdir}/{Path(args.input).stem}_radial_build.{save_format}", |
This is probably the correct and less-verbose way to do this in newer versions of Python (of course this would also make the import os redundant.
Contributor
Author
There was a problem hiding this comment.
Yes, you're right. Fixed
Collaborator
There was a problem hiding this comment.
Thank you very much :)
bf3029b to
1abed81
Compare
timothy-nunn
approved these changes
Dec 20, 2023
chris-ashe
pushed a commit
that referenced
this pull request
Apr 22, 2024
chris-ashe
pushed a commit
that referenced
this pull request
Apr 22, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Filename calculation in
plot_radial_build.pyis done taking the last 10 characters of the input file path.This behaviour is not safe and can lead to
NotFoundErrorto be thrown or cause path traversal in the worst case.The fix replaces the unsafe part picking up the basename of the file (without extension) and prepending it to
_radial_build.{save_format}static part.This also fixes
test_plot_radial_buildrun is some environments.Checklist
I confirm that I have completed the following checks: