Skip to content

Commit 68e9421

Browse files
AVRO-3985: adding default serializable pacakge to trusted package list
1 parent f20ed6f commit 68e9421

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,37 @@ public class SpecificDatumReader<T> extends GenericDatumReader<T> {
4141

4242
String userDefinedPackages = System.getProperty("org.apache.avro.SERIALIZABLE_PACKAGES", "");
4343

44-
// Combine the user-defined packages (if any) with the default packages.
45-
String combined = userProp.isEmpty() ? defaultPackages : userProp + "," + defaultPackages;
44+
if ("*".equals(userDefinedPackages)) {
45+
SERIALIZABLE_PACKAGES = new String[]{"*"};
46+
} else {
47+
String combinedPackages = userDefinedPackages.isEmpty() ? defaultPackages : userDefinedPackages + "," + defaultPackages;
4648

47-
SERIALIZABLE_PACKAGES = Arrays.stream(combined.split(","))
48-
.distinct()
49-
.toArray(String[]::new);
49+
SERIALIZABLE_PACKAGES = Arrays.stream(combinedPackages.split(","))
50+
.distinct()
51+
.toArray(String[]::new);
52+
}
5053
}
5154

5255
private final List<String> trustedPackages = new ArrayList<>();
5356

5457
public SpecificDatumReader() {
5558
this(null, null, SpecificData.get());
56-
initializeTrustedPackages();
5759
}
5860

5961
/** Construct for reading instances of a class. */
6062
public SpecificDatumReader(Class<T> c) {
6163
this(SpecificData.getForClass(c));
6264
setSchema(getSpecificData().getSchema(c));
63-
initializeTrustedPackages();
6465
}
6566

6667
/** Construct where the writer's and reader's schemas are the same. */
6768
public SpecificDatumReader(Schema schema) {
6869
this(schema, schema, SpecificData.getForSchema(schema));
69-
initializeTrustedPackages();
7070
}
7171

7272
/** Construct given writer's and reader's schema. */
7373
public SpecificDatumReader(Schema writer, Schema reader) {
7474
this(writer, reader, SpecificData.getForSchema(reader));
75-
initializeTrustedPackages();
7675
}
7776

7877
/**
@@ -91,17 +90,8 @@ public SpecificDatumReader(SpecificData data) {
9190

9291
/**
9392
* Initializes the {@code trustedPackages} list with the package names considered safe for deserialization.
94-
*
95-
* <p>This method populates the {@code trustedPackages} list using the static array {@code SERIALIZABLE_PACKAGES},
96-
* which is initialized from the system property {@code org.apache.avro.SERIALIZABLE_PACKAGES} combined with
97-
* default trusted packages. By doing so, it ensures that both user-defined and default packages are included,
98-
* and any duplicate entries are avoided.</p>
99-
*
100-
* <p>Before adding the packages, the list is cleared to prevent duplicate entries if this method is invoked
101-
* multiple times, ensuring that the list remains consistent and up-to-date across all instances.</p>
10293
*/
10394
private void initializeTrustedPackages() {
104-
trustedPackages.clear();
10595
trustedPackages.addAll(Arrays.asList(SERIALIZABLE_PACKAGES));
10696
}
10797

0 commit comments

Comments
 (0)