Skip to content
New issue

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

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

Already on GitHub? # to your account

HIVE-26539: Prevent unsafe deserialization in PartitionExpressionForM… #3605

Merged
merged 3 commits into from
Oct 18, 2022

Conversation

dengzhhu653
Copy link
Member

…etastore

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

TestMetastoreExpr/TestSerializationUtilities

Copy link
Contributor

@hsnusonic hsnusonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!
Can we add one unit test to check an exception will be thrown when the serialized object is not an instance of ExprNodeDesc?

@@ -228,6 +230,27 @@ public void setConf(Configuration conf) {
public Configuration getConf() {
return configuration;
}

@Override
public com.esotericsoftware.kryo.Registration getRegistration(Class type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure my understanding is correct, is this method called before the class being instantiated? So, we can avoid some classes be instantiated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, getRegistration is place for check whether an unregistered class is encountered when registrationRequired is set to true:
https://github.com/EsotericSoftware/kryo/blob/master/src/com/esotericsoftware/kryo/Kryo.java#L552-L556
However we cannot simply enable registrationRequired for UDF deserialization, as non-transient fields in the UDF are arbitrary, it's difficult to confine the inputs.
Thank you for the review and comments!

try (Input inp = new Input(new ByteArrayInputStream(bytes))) {
return (T) kryo.readClassAndObject(inp);
} finally {
kryo.setExprNodeFirst(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reset this field in releaseKryo()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug C 6 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 71 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Contributor

@hsnusonic hsnusonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dengzhhu653
Copy link
Member Author

@omalley Hi Owen, could you please also take a look at the changes? Thank you in advance!

@dengzhhu653 dengzhhu653 merged commit 60027bb into apache:master Oct 18, 2022
DongWei-4 pushed a commit to DongWei-4/hive that referenced this pull request Oct 28, 2022
dengzhhu653 added a commit to dengzhhu653/hive that referenced this pull request Dec 15, 2022
yeahyung pushed a commit to yeahyung/hive that referenced this pull request Jul 20, 2023
@dengzhhu653 dengzhhu653 deleted the HIVE-26539 branch November 26, 2024 07:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants