Skip to content

Commit

Permalink
Fix extraction of tar archives containing sparse files.
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 bazelbuild#20090.

Closes bazelbuild#20110.

PiperOrigin-RevId: 580935354
Change-Id: I6c9728ac3fd925432f44a55efaef8f5b52d428c0
  • Loading branch information
tjgq authored and copybara-github committed Nov 9, 2023
1 parent 99a3486 commit 93729f4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 26 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ maven.install(
"javax.inject:javax.inject:1",
"net.bytebuddy:byte-buddy-agent:1.14.5",
"net.bytebuddy:byte-buddy:1.14.5",
"org.apache.commons:commons-compress:1.19",
"org.apache.commons:commons-compress:1.20",
"org.apache.commons:commons-pool2:2.8.0",
"org.apache.tomcat:tomcat-annotations-api:8.0.5",
"org.apache.velocity:velocity:1.7",
Expand Down
25 changes: 6 additions & 19 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions maven_install.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": -271381572,
"__RESOLVED_ARTIFACTS_HASH": -474976451,
"__INPUT_ARTIFACTS_HASH": 1383287746,
"__RESOLVED_ARTIFACTS_HASH": -1510367107,
"conflict_resolution": {
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.9.0",
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.23.0",
Expand Down Expand Up @@ -570,9 +570,9 @@
},
"org.apache.commons:commons-compress": {
"shasums": {
"jar": "ff2d59fad74e867630fbc7daab14c432654712ac624dbee468d220677b124dd5"
"jar": "0aeb625c948c697ea7b205156e112363b59ed5e2551212cd4e460bdb72c7c06e"
},
"version": "1.19"
"version": "1.20"
},
"org.apache.commons:commons-pool2": {
"shasums": {
Expand Down
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 @@ -162,6 +164,63 @@ def testNewHttpTarArchiveWithSymlinks(self):
'@archive_with_symlink//:file-A',
])

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.

0 comments on commit 93729f4

Please sign in to comment.