(aws-s3-assets): `Asset` produces a corrupt ZIP if target `path` contains zero-byte file
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
I found this bug completely by accident. The scenario is as follows:
- Using an Nx generator to create a react application
- Nx generator creates an `assets` directory with a zero-byte `.gitkeep` file
- Using Nx to compile the app with webpack and output an `assets` directory with contents matching the prior bullet
- Using `@aws-cdk/aws-amplify-alpha` to initiate an Amplify app and deploy the generated app
```ts
const asset = new Asset(scope, 'Appt', { path: distPath });
const app = new Amplify.App(scope, appName, {
appName
});
const branch = app.addBranch(env, { asset });
...
```
Now, please don't be distracted by the scenario above - it only revealed the issue. In this scenario, `Asset` will create a zip file which contains the zero-byte file.
### Expected Behavior
A zip file created that's compatible with all aspects of of AWS services. Or, alternatively a warning that a ZIP file may not be compatible with some aspects of AWS.
### Current Behavior
When the errant zip file is used by CDK for deployment of the amplify app, the subsequent CloudFront deploy task fails with `FAILED`. The cloudfront logs for the deploy task contain the error: `only DEFLATED entries can have EXT descriptor`
It took some time to track this down to a zero byte file in the zip file. After some research, this seems to be quite a common problem with JVM apps which use `ZipInputStream`. Given AWS' proclivity for JVM use, I'd wager that some portion of the Amplify+CloudFront process is using a JVM app behind the scenes.
### Reproduction Steps
Please see the description section.
### Possible Solution
A workaround is to delete the zero-byte file manually. Or run a post-build or pre-deploy task that sanitizes the target directory.
An ideal solution would include one of or a combo of:
- `Asset` refusing to create a zip that contains a zero-byte file
- A warning when `Asset` is given a directory that contains a zero-byte file
### Additional Information/Context
I was able to verify that Amplify+Cloudfront have this same issue if you manually create the zip with the zero-byte file locally, upload it to s3, and then point an existing Amplify app to deploy from that zip file in s3 (directly or with url)
### CDK CLI Version
2.70.0
### Framework Version
2.70.0
### Node.js Version
18
### OS
MacOS Ventura
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start at the Asset entry point in the aws-s3-assets package and reproduce the archive behavior with a directory containing a zero-byte file. Inspect how the directory is zipped and verify that the resulting archive is accepted by the affected AWS deployment path, or that the issue reports a warning or refusal for this input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100