From 08b31dc8f93ce1d8b514f74746ed1c8684eb7994 Mon Sep 17 00:00:00 2001 From: Paul van Brouwershaven Date: Sun, 7 Jul 2024 16:37:29 +0200 Subject: [PATCH] Add error handling for context.InputFile.Seek operation --- sign/pdfxref.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sign/pdfxref.go b/sign/pdfxref.go index 343a6fd..b21eea9 100644 --- a/sign/pdfxref.go +++ b/sign/pdfxref.go @@ -29,10 +29,15 @@ func (context *SignContext) writeXref() error { } func (context *SignContext) writeXrefTable() error { + // Seek to the start of the xref table + _, err := context.InputFile.Seek(context.PDFReader.XrefInformation.StartPos, 0) + if err != nil { + return fmt.Errorf("failed to seek to xref table: %w", err) + } + // Read the existing xref table - context.InputFile.Seek(context.PDFReader.XrefInformation.StartPos, 0) xrefContent := make([]byte, context.PDFReader.XrefInformation.Length) - _, err := context.InputFile.Read(xrefContent) + _, err = context.InputFile.Read(xrefContent) if err != nil { return fmt.Errorf("failed to read xref table: %w", err) }