From ce3f941ad553ee388fddea7ec4b45df9efcb22bb Mon Sep 17 00:00:00 2001
From: Pompolic <pompolic@special-circumstanc.es>
Date: Tue, 28 Sep 2021 22:23:22 +0200
Subject: [PATCH] (WIP) consume remaining bits in input, if there are any

---
 lzw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lzw.c b/lzw.c
index b1bb161..5af4be4 100644
--- a/lzw.c
+++ b/lzw.c
@@ -281,12 +281,14 @@ void init_lzw_parser()
 	H_VRULE(LZW_11bitlitspec, h_bits(11, false));
 	H_VRULE(LZW_12bitlitspec, h_bits(12, false));
 
+	H_RULE(LZW_remainingbits, h_many(h_bits(1, false))); //XXX: could validate that these bits are 0?
+
 	H_VARULE(LZW_clear, h_choice(LZW_9bitlitspec, LZW_10bitlitspec, LZW_11bitlitspec, LZW_12bitlitspec, NULL)); //XXX: VARULE or AVRULE?
 	H_VRULE(LZW_eod, h_choice(LZW_9bitlitspec, LZW_10bitlitspec, LZW_11bitlitspec, LZW_12bitlitspec, NULL));
 	H_VRULE(LZW_literal, h_choice(LZW_9bitlitspec, LZW_10bitlitspec, LZW_11bitlitspec, LZW_12bitlitspec, NULL));
 	H_ARULE(LZW_codeword, h_choice(LZW_9bitcodeword, LZW_10bitcodeword, LZW_11bitcodeword, LZW_12bitcodeword, NULL));
 
-	H_RULE(LZW_data, h_sequence(LZW_clear, h_many1(h_choice(LZW_literal, LZW_clear, LZW_codeword, NULL)), LZW_eod, NULL)); //XXX: butnot eod
+	H_RULE(LZW_data, h_sequence(LZW_clear, h_many1(h_butnot(h_choice(LZW_literal, LZW_clear, LZW_codeword, NULL), LZW_eod)), LZW_eod, LZW_remainingbits, NULL));
 	p_lzwdata = LZW_data;
 }
 
-- 
GitLab