-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix panic when temp dir contains extra delimiters #279
base: master
Are you sure you want to change the base?
Conversation
@deitch, do you still maintain the library? Could please have a look at my PR as blocks my work. Btw, thanks for all the work you did for this library! :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the single comment.
test: image | ||
TEST_IMAGE=$(IMAGE) $(GOENV) go test $(GO_FILES) | ||
TEST_IMAGE=$(IMAGE) TMPDIR=/tmp//// $(GOENV) go test $(GO_FILES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few suggestions here:
First, I understand the desire to test this, but I am not sure this should be here vs inside the code itself. We want the base case to be clean.
I think a different approach might be to work with the places where it runs os.MkdirTemp()
and do os.SetEnv()
in the test files before calling those. Can you see if that works instead?
Second, we call os.MkdirTemp()
in one other place, squashfs. Take a look at a search for it.
Third, should we clean it up immediately after calling MkdirTemp()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deitch that's for your reply! The reason I did it like so I think you guessed right. I just have a very little experience working on/writing tests in go. You're suggestion is absolutely on point! Feels nice not only provide a fix but also learn something new.
Second, we call os.MkdirTemp() in one other place, squashfs. Take a look at a search for it.
That's a good question! It's not a crime to have multiple slashes in path and it is absolutely valid. In ideal world nothing should be affected by it. It's even described in unix specification: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271
A pathname can optionally contain one or more trailing <slash> characters. Multiple successive <slash> characters are considered to be the same as one <slash>, except for the case of exactly two leading <slash> characters.
So I think we shouldn't and it would be interesting to understand what exactly failing in this particular case. Some of external libraries, perhaps? Or if it's due to bug in this library then it should be definitely addressed as this is more like a workaround, not the ugliest though (as I believe some sort of data validation/normalisation is fine).
At the same time as any programmer I love when things work the same way and originate from the single source of truth. It won't hurt if I just introduce helper/wrapper of MkdirTemp function with extra sanity checks.
Do you lean any particular option? I probably slightly biased towards 2nd option as it looks more natural for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think we shouldn't and it would be interesting to understand what exactly failing in this particular case. Some of external libraries, perhaps? Or if it's due to bug in this library then it should be definitely addressed as this is more like a workaround, not the ugliest though (as I believe some sort of data validation/normalisation is fine)
You are correct, this is a better approach. I am reasonably confident that os.MkdirTemp()
is working fine, and something in our library (or an external library) is failing. Your stack trace indicates that it is failing at iso9660/finalize.go:960. That is an odd place to fail, as the only referenced var that could possibly be nil there is parentDirInfo
, defined here, which fills it from dirList
. I suspect that the parentDir
is slightly different from the key for the entry. Walk through it with dlv or put in some debugging printfs and check?
TMPDIR=/tmp// cause
iso9660.Create
to panicAfter fix
Encounter it on MacOS while experimenting with lima, more info here: lima-vm/lima#3150
I also made
go test
execute under scrambledTMPDIR
just in case it would happen someplace else in the codebase