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

Fixes for 449: Unexpected IOOBE handling #450

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ private final String _finishShortText(int len) throws IOException
final int[] codes = sUtf8UnitLengths;
do {
i = inputBuf[inPtr++] & 0xFF;
if (inPtr >= inputBuf.length) {
arthurscchan marked this conversation as resolved.
Show resolved Hide resolved
throw _constructError("Malformed UTF-8 character at end of short (non-chunked) text segment");
}
switch (codes[i]) {
case 0:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.fasterxml.jackson.dataformat.avro.fuzz;

import org.junit.Test;

import com.fasterxml.jackson.core.exc.StreamReadException;
import com.fasterxml.jackson.dataformat.avro.AvroFactory;
import com.fasterxml.jackson.dataformat.avro.AvroFactoryBuilder;
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
import com.fasterxml.jackson.dataformat.avro.AvroParser;
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

// [dataformats-binary#449]
public class Fuzz449_65618_IOOBETest
{
@Test
public void testFuzz65618IOOBE() throws Exception {
final AvroFactory factory = AvroFactory.builderWithApacheDecoder().build();
final AvroMapper mapper = new AvroMapper(factory);

final byte[] doc = {
(byte) 2, (byte) 22, (byte) 36, (byte) 2, (byte) 0,
(byte) 0, (byte) 8, (byte) 3, (byte) 3, (byte) 3,
(byte) 122, (byte) 3, (byte) -24
};

try (AvroParser p = factory.createParser(doc)) {
AvroSchemaGenerator gen = new AvroSchemaGenerator();
mapper.acceptJsonFormatVisitor(RootType.class, gen);
p.setSchema(gen.getGeneratedSchema());
p.getTextCharacters();
p.nextToken();
p.nextToken();
p.nextToken();
fail("Should not pass (invalid content)");
} catch (StreamReadException e) {
assertTrue(e.getMessage().contains("Malformed UTF-8 character"));
}
}

private class RootType {
public String name;
public int value;
}
}