Skip to content
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

Merged
merged 4 commits into from Jul 30, 2018

Conversation

rnorth
Copy link
Member

@rnorth rnorth commented Jul 29, 2018

No description provided.

@rnorth rnorth changed the title WIP: Fix #680: Avoid trailing slashes in tar entry filenames Fix #680: Avoid trailing slashes in tar entry filenames Jul 29, 2018
@rnorth rnorth added this to the next milestone Jul 29, 2018

private TarArchiveInputStream intoTarArchive(Consumer<TarArchiveOutputStream> consumer) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final TarArchiveOutputStream taos = new TarArchiveOutputStream(baos);
Copy link
Member

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) -> {
Copy link
Member

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
Copy link
Member

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

Copy link
Member Author

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.

@rnorth rnorth merged commit 3593c12 into master Jul 30, 2018
@rnorth rnorth deleted the fix-tar-entry-filename branch July 30, 2018 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants