Skip to content

Conversation

@bazel-io
Copy link
Member

updates the zipper utility so it can handle empty filelists. previously this would fail with

File  does not seem to exist.

(note the double space)

rather than being treated as an empty list ([]), an empty filelist was being treated as a non-empty list of length one with the only element being an empty string ([''])


Why on earth do I want this? I have a rule that outputs a zip file that may or may not be empty. There is no easy way to tell ahead of time if there will be files. The output could be optional, but that would make my life harder for reasons that I can't be bothered explaining (feel free to push on this if it's important). @bazel_tools//tools/zip:zipper fails if the filelist is empty and I am working around this by manually creating an empty zip file using the EOCD record:

if (files.length === 0) {
  fs.writeFileSync(zipFile, '\x50\x4b\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00');
}

it would be nice if I didn't have to do this :)

Closes #27008.

PiperOrigin-RevId: 812683346
Change-Id: Ifb7dc35b37ce9c07e53786206e90570da542fab7

Commit 349f6fb

updates the zipper utility so it can handle empty filelists. previously this would fail with

```
File  does not seem to exist.
```

(note the double space)

rather than being treated as an empty list (`[]`), an empty filelist was being treated as a non-empty list of length one with the only element being an empty string (`['']`)

---

Why on earth do I want this? I have a rule that outputs a zip file that may or may not be empty. There is no easy way to tell ahead of time if there will be files. The output *could* be optional, but that would make my life harder for reasons that I can't be bothered explaining (feel free to push on this if it's important). `@bazel_tools//tools/zip:zipper` fails if the filelist is empty and I am working around this by manually creating an empty zip file using the EOCD record:

```js
if (files.length === 0) {
  fs.writeFileSync(zipFile, '\x50\x4b\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00');
}
```

it would be nice if I didn't have to do this :)

Closes bazelbuild#27008.

PiperOrigin-RevId: 812683346
Change-Id: Ifb7dc35b37ce9c07e53786206e90570da542fab7
@bazel-io bazel-io requested a review from a team as a code owner January 26, 2026 09:57
@bazel-io bazel-io added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website awaiting-review PR is awaiting review from an assigned reviewer labels Jan 26, 2026
@bazel-io bazel-io requested a review from meteorcloudy January 26, 2026 09:57
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where the zipper utility would fail when provided with an empty filelist. The change correctly handles this case by treating an empty filelist as an empty set of files, allowing for the creation of an empty zip archive. A new test case is included to verify this behavior and prevent future regressions. While the overall approach is correct, I've identified a critical bug in the implementation that could lead to a crash due to a null pointer dereference if a memory allocation fails. Please address this issue.

@meteorcloudy meteorcloudy added this pull request to the merge queue Jan 26, 2026
Merged via the queue into bazelbuild:release-8.6.0 with commit fe199fb Jan 26, 2026
47 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants