From e51daf9a8144e6f3529c201711c8bbede7c642b9 Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Thu, 13 Jul 2017 21:59:39 +0200 Subject: [PATCH] Check if signature actually fits in file --- sign/pdfsignature.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sign/pdfsignature.go b/sign/pdfsignature.go index 7066d02..f37e627 100644 --- a/sign/pdfsignature.go +++ b/sign/pdfsignature.go @@ -241,6 +241,10 @@ func (context *SignContext) replaceSignature() error { dst := make([]byte, hex.EncodedLen(len(signature))) hex.Encode(dst, signature) + if uint32(len(dst)) > signatureMaxLength { + return errors.New("Signature is too big to fit in reserved space.") + } + context.OutputFile.WriteAt(dst, context.ByteRangeValues[0]+context.ByteRangeValues[1]+1) return nil