Skip to content

Commit

Permalink
[6.5.0] Fix extraction of tar archives containing sparse files. (#20531)
Browse files Browse the repository at this point in the history
By upgrading the Apache Commons Compress library to 1.20. I'm
deliberately not upgrading to the most recent one (1.24.0) because it
would require an additional JDK module (java.desktop) and significantly
regress the binary size.

Fixes #20090.

Closes #20110.

PiperOrigin-RevId: 580935354
Change-Id: I6c9728ac3fd925432f44a55efaef8f5b52d428c0

Co-authored-by: Tiago Quelhas <tjgq@google.com>
  • Loading branch information
Wyverald and tjgq authored Dec 14, 2023
1 parent f1aed7e commit 17d05dc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
63 changes: 61 additions & 2 deletions src/test/py/bazel/bazel_external_repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def StopHttpServer(self):
def setUp(self):
test_base.TestBase.setUp(self)
for f in [
'six-1.10.0.tar.gz', 'archive_with_symlink.zip',
'archive_with_symlink.tar.gz'
'six-1.10.0.tar.gz',
'archive_with_symlink.zip',
'archive_with_symlink.tar.gz',
'sparse_archive.tar',
]:
self.CopyFile(self.Rlocation('io_bazel/src/test/py/bazel/testdata/'
'bazel_external_repository_test/' + f), f)
Expand Down Expand Up @@ -167,6 +169,63 @@ def testNewHttpTarArchiveWithSymlinks(self):
])
self.assertEqual(exit_code, 0, os.linesep.join(stderr))

def testNewHttpTarWithSparseFile(self):
# Test extraction of tar archives containing sparse files.
# The archive under test was produced using GNU tar on Linux:
# truncate -s 1M sparse_file
# tar -c --sparse --format posix -f sparse_archive.tar sparse_file

ip, port = self._http_server.server_address
rule_definition = [
'load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")',
'http_archive(',
' name = "sparse_archive",',
' urls = ["http://%s:%s/sparse_archive.tar"],' % (ip, port),
' build_file = "@//:sparse_archive.BUILD",',
' sha256 = ',
(
' "a1a2b2ce4acd51a8cc1ab80adce6f134ac73e885219911a960a42000e312bb65",'
')'
),
]
rule_definition.extend(self.GetDefaultRepoRules())
self.ScratchFile('WORKSPACE', rule_definition)
self.ScratchFile(
'sparse_archive.BUILD',
[
'exports_files(["sparse_file"])',
],
)
self.ScratchFile(
'test.py',
[
'import sys',
'from tools.python.runfiles import runfiles',
'path = runfiles.Create().Rlocation(sys.argv[1])',
'if open(path, "rb").read() != b"\\0"*1024*1024:',
' sys.exit(1)',
],
)
self.ScratchFile(
'BUILD',
[
'py_test(',
' name = "test",',
' srcs = ["test.py"],',
(
' args = ["$(rlocationpath @sparse_archive//:sparse_file)"],'
' data = ['
),
' "@sparse_archive//:sparse_file",',
' "@bazel_tools//tools/python/runfiles",',
' ],)',
],
)
self.RunBazel([
'test',
'//:test',
])

def _CreatePyWritingStarlarkRule(self, print_string):
self.ScratchFile('repo/foo.bzl', [
'def _impl(ctx):',
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ distrib_java_import(
distrib_java_import(
name = "apache_commons_compress",
enable_distributions = ["debian"],
jars = ["apache_commons_compress/apache-commons-compress-1.19.jar"],
jars = ["apache_commons_compress/apache-commons-compress-1.20.jar"],
)

distrib_java_import(
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 17d05dc

Please sign in to comment.