-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #680: Avoid trailing slashes in tar entry filenames #808
Conversation
…trailing slashes
|
||
private TarArchiveInputStream intoTarArchive(Consumer<TarArchiveOutputStream> consumer) throws IOException { | ||
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
final TarArchiveOutputStream taos = new TarArchiveOutputStream(baos); |
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.
try-with-resources? Or @Cleanup
?
public void noTrailingSlashesInTarEntryNames() throws Exception { | ||
final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt"); | ||
|
||
final TarArchiveInputStream tais = intoTarArchive((taos) -> { |
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.
@Cleanup
?
final TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, entryFilename + "/" + relativePathToSourceFile); // entry filename e.g. /xyz/bar/baz | ||
final String tarEntryFilename; | ||
if (relativePathToSourceFile.isEmpty()) { | ||
tarEntryFilename = entryFilename; // entry filename e.g. xyz => xyz |
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 wonder what will happen if the user will call with it /some/entry
?
Maybe we should strip /
prefix from tarEntryFilename
before passing to TarArchiveEntry
's constructor, for the additional safety
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.
Hmm, I think it's allowed, isn't it? There's no source 'working directory' in this context, so 'abc' == '/abc'
..?
I'll give it a try though.
No description provided.