Skip to content

Commit fba876b

Browse files
ccaominhfjy
authored andcommitted
Update jackson to 2.9.10 (#8940)
Addresses security vulnerabilities: - sonatype-2016-0397: FasterXML/jackson-core#315 - sonatype-2017-0355: FasterXML/jackson-core#322
1 parent adb72fe commit fba876b

File tree

11 files changed

+86
-76
lines changed

11 files changed

+86
-76
lines changed

core/src/main/java/org/apache/druid/timeline/SegmentWithOvershadowedStatus.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,25 @@ public class SegmentWithOvershadowedStatus implements Comparable<SegmentWithOver
3434
private final boolean overshadowed;
3535
/**
3636
* dataSegment is serialized "unwrapped", i.e. it's properties are included as properties of
37-
* enclosing class. If in future, if {@Code SegmentWithOvershadowedStatus} were to extend {@link DataSegment},
37+
* enclosing class. If in future, if {@code SegmentWithOvershadowedStatus} were to extend {@link DataSegment},
3838
* there will be no change in the serialized format.
3939
*/
4040
@JsonUnwrapped
4141
private final DataSegment dataSegment;
4242

4343
@JsonCreator
4444
public SegmentWithOvershadowedStatus(
45-
@JsonProperty("dataSegment") DataSegment dataSegment,
4645
@JsonProperty("overshadowed") boolean overshadowed
4746
)
47+
{
48+
// Jackson will overwrite dataSegment if needed (even though the field is final)
49+
this(null, overshadowed);
50+
}
51+
52+
public SegmentWithOvershadowedStatus(
53+
DataSegment dataSegment,
54+
boolean overshadowed
55+
)
4856
{
4957
this.dataSegment = dataSegment;
5058
this.overshadowed = overshadowed;
@@ -94,4 +102,13 @@ public int compareTo(SegmentWithOvershadowedStatus o)
94102
{
95103
return dataSegment.getId().compareTo(o.dataSegment.getId());
96104
}
105+
106+
@Override
107+
public String toString()
108+
{
109+
return "SegmentWithOvershadowedStatus{" +
110+
"overshadowed=" + overshadowed +
111+
", dataSegment=" + dataSegment +
112+
'}';
113+
}
97114
}

core/src/test/java/org/apache/druid/data/input/impl/ParseSpecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void testBadTypeSerde() throws IOException
206206

207207
expectedException.expect(IllegalArgumentException.class);
208208
expectedException.expectCause(CoreMatchers.instanceOf(JsonMappingException.class));
209-
expectedException.expectMessage("Could not resolve type id 'foo' into a subtype");
209+
expectedException.expectMessage("Could not resolve type id 'foo' as a subtype");
210210
mapper.convertValue(mapValue, ParseSpec.class);
211211
}
212212
}

core/src/test/java/org/apache/druid/timeline/SegmentWithOvershadowedStatusTest.java

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.druid.timeline.partition.ShardSpec;
3535
import org.joda.time.Interval;
3636
import org.junit.Assert;
37-
import org.junit.Before;
3837
import org.junit.Test;
3938

4039
import javax.annotation.Nullable;
@@ -44,28 +43,29 @@
4443

4544
public class SegmentWithOvershadowedStatusTest
4645
{
47-
private static final ObjectMapper MAPPER = new TestObjectMapper();
46+
private static final ObjectMapper MAPPER = createObjectMapper();
47+
private static final Interval INTERVAL = Intervals.of("2011-10-01/2011-10-02");
48+
private static final ImmutableMap<String, Object> LOAD_SPEC = ImmutableMap.of("something", "or_other");
49+
private static final boolean OVERSHADOWED = true;
4850
private static final int TEST_VERSION = 0x9;
51+
private static final SegmentWithOvershadowedStatus SEGMENT = createSegmentWithOvershadowedStatus();
4952

50-
@Before
51-
public void setUp()
53+
private static ObjectMapper createObjectMapper()
5254
{
55+
ObjectMapper objectMapper = new TestObjectMapper();
5356
InjectableValues.Std injectableValues = new InjectableValues.Std();
5457
injectableValues.addValue(PruneSpecsHolder.class, PruneSpecsHolder.DEFAULT);
55-
MAPPER.setInjectableValues(injectableValues);
58+
objectMapper.setInjectableValues(injectableValues);
59+
return objectMapper;
5660
}
5761

58-
@Test
59-
public void testUnwrappedSegmentWithOvershadowedStatusDeserialization() throws Exception
62+
private static SegmentWithOvershadowedStatus createSegmentWithOvershadowedStatus()
6063
{
61-
final Interval interval = Intervals.of("2011-10-01/2011-10-02");
62-
final ImmutableMap<String, Object> loadSpec = ImmutableMap.of("something", "or_other");
63-
64-
final DataSegment dataSegment = new DataSegment(
64+
DataSegment dataSegment = new DataSegment(
6565
"something",
66-
interval,
66+
INTERVAL,
6767
"1",
68-
loadSpec,
68+
LOAD_SPEC,
6969
Arrays.asList("dim1", "dim2"),
7070
Arrays.asList("met1", "met2"),
7171
NoneShardSpec.instance(),
@@ -74,42 +74,58 @@ public void testUnwrappedSegmentWithOvershadowedStatusDeserialization() throws E
7474
1
7575
);
7676

77-
final SegmentWithOvershadowedStatus segment = new SegmentWithOvershadowedStatus(dataSegment, false);
77+
return new SegmentWithOvershadowedStatus(dataSegment, OVERSHADOWED);
78+
}
7879

80+
@Test
81+
public void testUnwrappedSegmentWithOvershadowedStatusDeserialization() throws Exception
82+
{
7983
final Map<String, Object> objectMap = MAPPER.readValue(
80-
MAPPER.writeValueAsString(segment),
84+
MAPPER.writeValueAsString(SEGMENT),
8185
JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT
8286
);
8387

8488
Assert.assertEquals(11, objectMap.size());
8589
Assert.assertEquals("something", objectMap.get("dataSource"));
86-
Assert.assertEquals(interval.toString(), objectMap.get("interval"));
90+
Assert.assertEquals(INTERVAL.toString(), objectMap.get("interval"));
8791
Assert.assertEquals("1", objectMap.get("version"));
88-
Assert.assertEquals(loadSpec, objectMap.get("loadSpec"));
92+
Assert.assertEquals(LOAD_SPEC, objectMap.get("loadSpec"));
8993
Assert.assertEquals("dim1,dim2", objectMap.get("dimensions"));
9094
Assert.assertEquals("met1,met2", objectMap.get("metrics"));
9195
Assert.assertEquals(ImmutableMap.of("type", "none"), objectMap.get("shardSpec"));
9296
Assert.assertEquals(TEST_VERSION, objectMap.get("binaryVersion"));
9397
Assert.assertEquals(1, objectMap.get("size"));
94-
Assert.assertEquals(false, objectMap.get("overshadowed"));
98+
Assert.assertEquals(OVERSHADOWED, objectMap.get("overshadowed"));
9599

96-
final String json = MAPPER.writeValueAsString(segment);
100+
final String json = MAPPER.writeValueAsString(SEGMENT);
97101

98102
final TestSegmentWithOvershadowedStatus deserializedSegment = MAPPER.readValue(
99103
json,
100104
TestSegmentWithOvershadowedStatus.class
101105
);
102106

103-
Assert.assertEquals(segment.getDataSegment().getDataSource(), deserializedSegment.getDataSource());
104-
Assert.assertEquals(segment.getDataSegment().getInterval(), deserializedSegment.getInterval());
105-
Assert.assertEquals(segment.getDataSegment().getVersion(), deserializedSegment.getVersion());
106-
Assert.assertEquals(segment.getDataSegment().getLoadSpec(), deserializedSegment.getLoadSpec());
107-
Assert.assertEquals(segment.getDataSegment().getDimensions(), deserializedSegment.getDimensions());
108-
Assert.assertEquals(segment.getDataSegment().getMetrics(), deserializedSegment.getMetrics());
109-
Assert.assertEquals(segment.getDataSegment().getShardSpec(), deserializedSegment.getShardSpec());
110-
Assert.assertEquals(segment.getDataSegment().getSize(), deserializedSegment.getSize());
111-
Assert.assertEquals(segment.getDataSegment().getId(), deserializedSegment.getId());
107+
DataSegment dataSegment = SEGMENT.getDataSegment();
108+
Assert.assertEquals(dataSegment.getDataSource(), deserializedSegment.getDataSource());
109+
Assert.assertEquals(dataSegment.getInterval(), deserializedSegment.getInterval());
110+
Assert.assertEquals(dataSegment.getVersion(), deserializedSegment.getVersion());
111+
Assert.assertEquals(dataSegment.getLoadSpec(), deserializedSegment.getLoadSpec());
112+
Assert.assertEquals(dataSegment.getDimensions(), deserializedSegment.getDimensions());
113+
Assert.assertEquals(dataSegment.getMetrics(), deserializedSegment.getMetrics());
114+
Assert.assertEquals(dataSegment.getShardSpec(), deserializedSegment.getShardSpec());
115+
Assert.assertEquals(dataSegment.getSize(), deserializedSegment.getSize());
116+
Assert.assertEquals(dataSegment.getId(), deserializedSegment.getId());
117+
}
112118

119+
// Previously, the implementation of SegmentWithOvershadowedStatus had @JsonCreator/@JsonProperty and @JsonUnwrapped
120+
// on the same field (dataSegment), which used to work in Jackson 2.6, but does not work with Jackson 2.9:
121+
// https://github.com/FasterXML/jackson-databind/issues/265#issuecomment-264344051
122+
@Test
123+
public void testJsonCreatorAndJsonUnwrappedAnnotationsAreCompatible() throws Exception
124+
{
125+
String json = MAPPER.writeValueAsString(SEGMENT);
126+
SegmentWithOvershadowedStatus segment = MAPPER.readValue(json, SegmentWithOvershadowedStatus.class);
127+
Assert.assertEquals(SEGMENT, segment);
128+
Assert.assertEquals(json, MAPPER.writeValueAsString(segment));
113129
}
114130
}
115131

indexing-hadoop/src/main/java/org/apache/druid/indexer/IndexGeneratorJob.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import java.io.File;
7878
import java.io.FileNotFoundException;
7979
import java.io.IOException;
80+
import java.io.InputStream;
8081
import java.nio.ByteBuffer;
8182
import java.util.ArrayList;
8283
import java.util.Iterator;
@@ -117,7 +118,7 @@ public static List<DataSegment> getPublishedSegments(HadoopDruidIndexerConfig co
117118
FileSystem fs = descriptorInfoDir.getFileSystem(conf);
118119

119120
for (FileStatus status : fs.listStatus(descriptorInfoDir)) {
120-
final DataSegment segment = jsonMapper.readValue(fs.open(status.getPath()), DataSegment.class);
121+
final DataSegment segment = jsonMapper.readValue((InputStream) fs.open(status.getPath()), DataSegment.class);
121122
publishedSegmentsBuilder.add(segment);
122123
log.info("Adding segment %s to the list of published segments", segment.getId());
123124
}

integration-tests/src/test/resources/results/auth_test_sys_schema_segments.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"is_available": 1,
1414
"is_realtime": 0,
1515
"is_overshadowed": 0,
16-
"payload": "{\"dataSource\":\"auth_test\",\"interval\":\"2012-12-29T00:00:00.000Z/2013-01-10T08:00:00.000Z\",\"version\":\"2013-01-10T08:13:47.830Z_v9\",\"loadSpec\":{\"load spec is pruned, because it's not needed on Brokers, but eats a lot of heap space\":\"\"},\"dimensions\":\"anonymous,area_code,city,continent_code,country_name,dma_code,geo,language,namespace,network,newpage,page,postal_code,region_lookup,robot,unpatrolled,user\",\"metrics\":\"added,count,deleted,delta,delta_hist,unique_users,variation\",\"shardSpec\":{\"type\":\"none\"},\"binaryVersion\":9,\"size\":446027801,\"identifier\":\"auth_test_2012-12-29T00:00:00.000Z_2013-01-10T08:00:00.000Z_2013-01-10T08:13:47.830Z_v9\",\"overshadowed\":false}"
16+
"payload": "{\"overshadowed\":false,\"dataSource\":\"auth_test\",\"interval\":\"2012-12-29T00:00:00.000Z/2013-01-10T08:00:00.000Z\",\"version\":\"2013-01-10T08:13:47.830Z_v9\",\"loadSpec\":{\"load spec is pruned, because it's not needed on Brokers, but eats a lot of heap space\":\"\"},\"dimensions\":\"anonymous,area_code,city,continent_code,country_name,dma_code,geo,language,namespace,network,newpage,page,postal_code,region_lookup,robot,unpatrolled,user\",\"metrics\":\"added,count,deleted,delta,delta_hist,unique_users,variation\",\"shardSpec\":{\"type\":\"none\"},\"binaryVersion\":9,\"size\":446027801,\"identifier\":\"auth_test_2012-12-29T00:00:00.000Z_2013-01-10T08:00:00.000Z_2013-01-10T08:13:47.830Z_v9\"}"
1717
}
1818
]

licenses.yaml

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@ name: Jackson
196196
license_category: binary
197197
module: java-core
198198
license_name: Apache License version 2.0
199-
version: 2.6.7
199+
version: 2.9.10
200200
libraries:
201201
- com.fasterxml.jackson.core: jackson-annotations
202202
- com.fasterxml.jackson.core: jackson-core
203+
- com.fasterxml.jackson.core: jackson-databind
203204
- com.fasterxml.jackson.dataformat: jackson-dataformat-cbor
204205
- com.fasterxml.jackson.dataformat: jackson-dataformat-smile
205206
- com.fasterxml.jackson.datatype: jackson-datatype-guava
@@ -232,37 +233,6 @@ notice: |
232233
233234
---
234235

235-
name: Jackson
236-
license_category: binary
237-
module: java-core
238-
license_name: Apache License version 2.0
239-
version: 2.6.7.3
240-
libraries:
241-
- com.fasterxml.jackson.core: jackson-databind
242-
notice: |
243-
# Jackson JSON processor
244-
245-
Jackson is a high-performance, Free/Open Source JSON processing library.
246-
It was originally written by Tatu Saloranta ([email protected]), and has
247-
been in development since 2007.
248-
It is currently developed by a community of developers, as well as supported
249-
commercially by FasterXML.com.
250-
251-
## Licensing
252-
253-
Jackson core and extension components may licensed under different licenses.
254-
To find the details that apply to this artifact see the accompanying LICENSE file.
255-
For more information, including possible other licensing options, contact
256-
FasterXML.com (http://fasterxml.com).
257-
258-
## Credits
259-
260-
A list of contributors may be found from CREDITS file, which is included
261-
in some artifacts (usually source distributions); but is always available
262-
from the source code management (SCM) system project uses.
263-
264-
---
265-
266236
name: Caffeine
267237
license_category: binary
268238
module: java-core
@@ -1165,7 +1135,7 @@ name: Apache Calcite Avatica
11651135
license_category: binary
11661136
module: java-core
11671137
license_name: Apache License version 2.0
1168-
version: 1.12.0
1138+
version: 1.15.0
11691139
libraries:
11701140
- org.apache.calcite.avatica: avatica-core
11711141
- org.apache.calcite.avatica: avatica-metrics

pom.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<aether.version>0.9.0.M2</aether.version>
7979
<apache.curator.version>4.1.0</apache.curator.version>
8080
<apache.curator.test.version>2.12.0</apache.curator.test.version>
81-
<avatica.version>1.12.0</avatica.version>
81+
<avatica.version>1.15.0</avatica.version>
8282
<avro.version>1.9.1</avro.version>
8383
<calcite.version>1.21.0</calcite.version>
8484
<derby.version>10.14.2.0</derby.version>
@@ -88,8 +88,7 @@
8888
<hamcrest.version>1.3</hamcrest.version>
8989
<jetty.version>9.4.12.v20180830</jetty.version>
9090
<jersey.version>1.19.3</jersey.version>
91-
<!-- jackson 2.7.x causes injection error and 2.8.x can't be used because avatica is using 2.6.3 -->
92-
<jackson.version>2.6.7</jackson.version>
91+
<jackson.version>2.9.10</jackson.version>
9392
<codehaus.jackson.version>1.9.13</codehaus.jackson.version>
9493
<log4j.version>2.8.2</log4j.version>
9594
<netty3.version>3.10.6.Final</netty3.version>
@@ -429,7 +428,7 @@
429428
<dependency>
430429
<groupId>com.fasterxml.jackson.core</groupId>
431430
<artifactId>jackson-databind</artifactId>
432-
<version>${jackson.version}.3</version>
431+
<version>${jackson.version}</version>
433432
</dependency>
434433
<dependency>
435434
<groupId>com.fasterxml.jackson.datatype</groupId>
@@ -441,6 +440,15 @@
441440
<artifactId>jackson-datatype-joda</artifactId>
442441
<version>${jackson.version}</version>
443442
</dependency>
443+
<dependency>
444+
<!--
445+
~ This is a transitive dependency of com.amazonaws:aws-java-sdk-core. Override the version here so
446+
~ that it is the same as the other jackson dependencies.
447+
-->
448+
<groupId>com.fasterxml.jackson.dataformat</groupId>
449+
<artifactId>jackson-dataformat-cbor</artifactId>
450+
<version>${jackson.version}</version>
451+
</dependency>
444452
<dependency>
445453
<groupId>com.fasterxml.jackson.dataformat</groupId>
446454
<artifactId>jackson-dataformat-smile</artifactId>

processing/src/test/java/org/apache/druid/query/select/SelectQueryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testSerde() throws Exception
5353
{
5454
final String exceptionMessage =
5555
StringUtils.format(
56-
"Instantiation of [simple type, class org.apache.druid.query.select.SelectQuery] value failed: %s",
56+
"Cannot construct instance of `org.apache.druid.query.select.SelectQuery`, problem: %s",
5757
SelectQuery.REMOVED_ERROR_MESSAGE
5858
);
5959
expectedException.expect(JsonMappingException.class);

server/src/test/java/org/apache/druid/guice/FirehoseModuleTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.apache.druid.guice;
2121

22-
import com.fasterxml.jackson.databind.AnnotationIntrospector;
2322
import com.fasterxml.jackson.databind.Module;
2423
import com.fasterxml.jackson.databind.ObjectMapper;
2524
import com.fasterxml.jackson.databind.cfg.MapperConfig;
@@ -69,8 +68,7 @@ private static Set<Class> getFirehoseFactorySubtypeClasses(ObjectMapper objectMa
6968
{
7069
Class parentClass = FirehoseFactory.class;
7170
MapperConfig config = objectMapper.getDeserializationConfig();
72-
AnnotationIntrospector annotationIntrospector = config.getAnnotationIntrospector();
73-
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(parentClass, annotationIntrospector, config);
71+
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(parentClass, config);
7472
Collection<NamedType> subtypes = objectMapper.getSubtypeResolver().collectAndResolveSubtypesByClass(config, ac);
7573
Assert.assertNotNull(subtypes);
7674
return subtypes.stream()

server/src/test/java/org/apache/druid/segment/indexing/DataSchemaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void testSerdeWithInvalidParserMap() throws Exception
282282
expectedException.expect(CoreMatchers.instanceOf(IllegalArgumentException.class));
283283
expectedException.expectCause(CoreMatchers.instanceOf(JsonMappingException.class));
284284
expectedException.expectMessage(
285-
"Instantiation of [simple type, class org.apache.druid.data.input.impl.StringInputRowParser] value failed: parseSpec"
285+
"Cannot construct instance of `org.apache.druid.data.input.impl.StringInputRowParser`, problem: parseSpec"
286286
);
287287

288288
// Jackson creates a default type parser (StringInputRowParser) for an invalid type.

0 commit comments

Comments
 (0)