Skip to content

Commit

Permalink
fix(cdk-graph-plugin-diagram): cap svg size at 10k
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyJonas committed Mar 8, 2023
1 parent fc0a36a commit 33ecda3
Show file tree
Hide file tree
Showing 26 changed files with 633 additions and 15 deletions.
7 changes: 4 additions & 3 deletions packages/cdk-graph-plugin-diagram/src/internal/utils/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export async function convertSvgImageDefsFromSvgToPng(
const png = sharp(
AwsArchitecture.resolveAssetPath(
AwsArchitecture.formatAssetPath(assetKey, "png")
)
),
{ limitInputPixels: false }
);
const pngBuffer = await png
.resize({
Expand All @@ -66,7 +67,7 @@ export async function convertSvg(
outputFile: string
): Promise<void> {
const resolvedSvg = await convertSvgImageDefsFromSvgToPng(svgString);
await sharp(Buffer.from(resolvedSvg))
await sharp(Buffer.from(resolvedSvg), { limitInputPixels: false })
.trim({ background: "transparent" })
.toFile(outputFile);
}
Expand Down Expand Up @@ -275,7 +276,7 @@ export function reconcileViewBox(svg: svgson.INode): string {
};

// Max allowed by sharp: https://github.com/lovell/sharp/blob/2c465282699432299c478ba00ab825e07d9bdab0/src/pipeline.cc#L288
const MAX_SVG = 32760; // 32767 is max, but leaving a small buffer
const MAX_SVG = 10000; // 32767 is max width & height in sharp, but capping at 10k for perf and downscale huge diagrams

if (scaledViewBox.width && scaledViewBox.width > MAX_SVG) {
const downscale = MAX_SVG / scaledViewBox.width;
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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

0 comments on commit 33ecda3

Please sign in to comment.