Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding is not handled gracefully #31

Open
maleadt opened this issue Jun 17, 2024 · 0 comments
Open

Padding is not handled gracefully #31

maleadt opened this issue Jun 17, 2024 · 0 comments

Comments

@maleadt
Copy link

maleadt commented Jun 17, 2024

MWE:

using CodecBzip2: transcode, Bzip2Compressor, Bzip2Decompressor

function main()
    # generate some data
    input = Pipe()
    output = Pipe()
    cmd = `bzip2`
    proc = run(pipeline(cmd, stdout=output, stdin=input); wait=false)
    close(output.in)
    writer = @async begin
        write(input, "Hello, world!")
        close(input)
    end
    reader = @async read(output)
    wait(proc)
    compressed = fetch(reader)

    # add some padding
    push!(compressed, 0)

    # verify we can decompress using `bunzip2`
    mktempdir() do dir
        path = joinpath(dir, "test.bz2")
        write(path, compressed)
        run(`bunzip2 $path`)
        println(read(joinpath(dir, "test"), String))
    end

    uncompressed = transcode(Bzip2Decompressor, compressed)
    String(uncompressed)
end

The bunzip2 tool generates a warning, but continues to decompress:

bunzip2: /var/folders/5m/zq0fq7r91f7_5qb1c31vgy5h0000gn/T/jl_B16lhs/test.bz2: trailing garbage after EOF ignored
Hello, world!

CodecBzip2.jl fails:

ERROR: CodecBzip2.BZ2Error(-5)

... where -5 seems to be BZ_DATA_ERROR_MAGIC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant