Bug with the zip fs provider (7u72, 8u25), am able to create a corrupted zip...

Francis Galiegue fgaliegue at gmail.com
Thu Jan 15 00:42:46 UTC 2015


Unfortunately I cannot write a real SSCCE. I discovered it using
jackson-databind 2.5.0...

This simple code generates an invalid zip file; no exceptions thrown:

public static void main(final String... args)
    throws IOException
{
    final Map<String, String> map
        = Collections.singletonMap("create", "true");
    final Path zipfile = Paths.get("/tmp/foo.zip");
    Files.deleteIfExists(zipfile);
    final URI uri = URI.create("jar:" + zipfile.toUri());
    final ObjectMapper mapper = new ObjectMapper();

    try (
        final FileSystem zipfs = FileSystems.newFileSystem(uri, map);
        final OutputStream out
            = Files.newOutputStream(zipfs.getPath("/t.json"));
    ) {
        mapper.writeValue(out, "hello");
    }
}

When I try and unzip, I get:

$ unzip /tmp/foo.zip
Archive:  /tmp/foo.zip
replace t.json? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
  inflating: t.json
  error:  invalid compressed data to inflate

Ubuntu 14.10, x86_64; underlying fs is btrfs.

A way to work around this with Jackson proper is to disable
JsonGenerator.Feature.AUTO_CLOSE_SOURCE, which closes the stream for
you.

I tried and wrote code which closes the stream twice, without
try-with-resources etc... Nothing. This code is really the only way I
can reproduce this bug...

-- 
Francis Galiegue, fgaliegue at gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)


More information about the nio-dev mailing list