~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH hare-compress 1/2] compress::deflate: Fix off-by-one size of counts array

Details
Message ID
<3b35d3169db9cf8efaa4c8c886f5221343b22885.1678501602.git.lassi@pulk.fi>
DKIM signature
pass
Download raw message
Patch: +3 -3
The highest index of the array should be MAXBITS,
hence length = MAXBITS + 1.

Signed-off-by: Lassi Pulkkinen <lassi@pulk.fi>
---
 compress/flate/inflate.ha | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compress/flate/inflate.ha b/compress/flate/inflate.ha
index 2f3a5f4..fd3e9c9 100644
--- a/compress/flate/inflate.ha
+++ b/compress/flate/inflate.ha
@@ -25,7 +25,7 @@ const fixed_dist: huffman = huffman {
};

export type huffman = struct {
	counts: [MAXBITS]u16,
	counts: [MAXBITS + 1]u16,
	symbols: [MAXCODES]u16,
};

@@ -170,7 +170,7 @@ fn copy(d: *decompressor, back: size, n: size) (void | io::error) = {

fn decode(d: *decompressor, h: huffman) (u16 | io::error) = {
	let code = 0u32, index = 0u32, first = 0u32;
	for (let i = 1z; i < MAXBITS; i += 1) {
	for (let i = 1z; i <= MAXBITS; i += 1) {
		code |= bits(d, 1)?;
		if (code < first + h.counts[i]) {
			return h.symbols[index + (code - first)];
@@ -190,7 +190,7 @@ fn construct(h: *huffman, lens: []u16) (void | io::error) = {
	};
	if (h.counts[0] == len(lens)) return;

	for (let left = 1z, i = 1z; i < MAXBITS; i += 1) {
	for (let left = 1z, i = 1z; i <= MAXBITS; i += 1) {
		left <<= 1;
		left -= h.counts[i];
		if (left < 0) return wraperror(inflate_err::HUFFMAN);
-- 
2.39.2

[PATCH hare-compress 2/2] compress::deflate: Fix < 0 check on unsigned int

Details
Message ID
<3e7bfa927fb264acd70192061f4a5cdcc14ed4ab.1678501602.git.lassi@pulk.fi>
In-Reply-To
<3b35d3169db9cf8efaa4c8c886f5221343b22885.1678501602.git.lassi@pulk.fi> (view parent)
DKIM signature
pass
Download raw message
Patch: +1 -1
Signed-off-by: Lassi Pulkkinen <lassi@pulk.fi>
---
 compress/flate/inflate.ha | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compress/flate/inflate.ha b/compress/flate/inflate.ha
index fd3e9c9..046ac18 100644
--- a/compress/flate/inflate.ha
+++ b/compress/flate/inflate.ha
@@ -192,8 +192,8 @@ fn construct(h: *huffman, lens: []u16) (void | io::error) = {

	for (let left = 1z, i = 1z; i <= MAXBITS; i += 1) {
		left <<= 1;
		if (left < h.counts[i]) return wraperror(inflate_err::HUFFMAN);
		left -= h.counts[i];
		if (left < 0) return wraperror(inflate_err::HUFFMAN);
	};

	let offs: [MAXBITS + 1]u16 = [0...];
-- 
2.39.2

Re: [PATCH hare-compress 2/2] compress::deflate: Fix < 0 check on unsigned int

Details
Message ID
<CR7OVRWZB90Y.U3YCVN7UWMKV@taiga>
In-Reply-To
<3e7bfa927fb264acd70192061f4a5cdcc14ed4ab.1678501602.git.lassi@pulk.fi> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/hare-compress
   4a86362..159eb2b  master -> master
Reply to thread Export thread (mbox)