Signed integer overflow in Sfixnum after LZ4 decompression

Open Beginner friendly
#1,110 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
compilers

Research direction

Start in c/new-io.c at the decompression path that calls LZ4_decompress_safe and returns Sfixnum(r); read the surrounding bytevector-uncompress handling to see how the byte count is scaled by the fixnum tag. Check whether other size conversions in the same file have the same 32-bit-int overflow shape, then build and run the bytevector-uncompress repro on a 64-bit build with compress-format 'lz4. Done means a decompression of 2^28 bytes returns the correct length without signed overflow.

Written by the indexing model from the issue text.

Description

In c/new-io.c, the return value of LZ4_decompress_safe is converted using:

return Sfixnum(r);

On ta6nt, int is 32 bits and Sfixnum(r) computes r * 8 before casting. A successful LZ4 decompression returning at least 268,435,456 bytes therefore triggers signed overflow. Casting r to iptr before the multiplication fixes this on 64-bit builds.

eg.

(import (chezscheme))
(parameterize ([compress-format 'lz4] [compress-level 'low])
  (write (bytevector-length (bytevector-uncompress (bytevector-compress (make-bytevector (expt 2 28) 0))))))
Dominant language
Scheme
Stars
7.4k
Forks
1k
Avg merge
1d 20h
Merged PRs (30d)
19

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cisco/ChezScheme

All issues in cisco/ChezScheme

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.