From 11f3a6e7a2ca69fbf317bc69173bbf59f1dfb8f8 Mon Sep 17 00:00:00 2001 From: Gunnsteinn Hall Date: Thu, 16 Apr 2020 23:05:50 +0000 Subject: [PATCH] Fix for crash in CCITT decoder. Resolves https://github.com/unidoc/unipdf/issues/314 (#315) --- internal/ccittfax/encoder.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/ccittfax/encoder.go b/internal/ccittfax/encoder.go index a8ac5e5e..97cf2daf 100644 --- a/internal/ccittfax/encoder.go +++ b/internal/ccittfax/encoder.go @@ -412,6 +412,11 @@ func seekChangingElem(row []byte, currElem int) int { if currElem >= len(row) { return currElem } + if currElem < -1 { + // A current element of -1 means white color starting prior to first element (0). + // Should not be able to go any further left than that. + currElem = -1 + } var color byte if currElem > -1 {