Skip to content

Commit 1dc956d

Browse files
fix: serve exact PDF bytes in preview routes, not Node's shared buffer pool
Buffer.buffer on pooled small buffers returns the whole 8KB pool with a non-zero offset, so preview PDFs started with garbage instead of %PDF- and the iframe viewer on the sign page failed to render. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 884d131 commit 1dc956d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

  • asmita/src/app/api/cases/[caseId]

asmita/src/app/api/cases/[caseId]/preview-hash-advisory/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export async function GET(
8282
date: new Date().toLocaleDateString("en-IN", { year: "numeric", month: "long", day: "numeric" }),
8383
});
8484

85-
return new NextResponse(pdfBytes.buffer as ArrayBuffer, {
85+
// Copy into an exact-sized buffer: Buffer.buffer may be Node's shared 8KB
86+
// pool with a non-zero offset, which serves garbage bytes around the PDF.
87+
return new NextResponse(new Uint8Array(pdfBytes), {
8688
headers: {
8789
"Content-Type": "application/pdf",
8890
"Content-Disposition": `inline; filename="hash-advisory-preview-${record.referenceNumber}.pdf"`,

asmita/src/app/api/cases/[caseId]/preview-notice/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export async function GET(
7878
date: new Date().toLocaleDateString("en-IN", { year: "numeric", month: "long", day: "numeric" }),
7979
});
8080

81-
return new NextResponse(pdfBytes.buffer as ArrayBuffer, {
81+
// Copy into an exact-sized buffer: Buffer.buffer may be Node's shared 8KB
82+
// pool with a non-zero offset, which serves garbage bytes around the PDF.
83+
return new NextResponse(new Uint8Array(pdfBytes), {
8284
headers: {
8385
"Content-Type": "application/pdf",
8486
"Content-Disposition": `inline; filename="notice-preview-${record.referenceNumber}.pdf"`,

0 commit comments

Comments
 (0)