Skip to content

Conversation

@Shivam7-1
Copy link

Issue link: https://issues.oss-fuzz.com/issues/375660994
Added validation for attribute name and length in readAttribute method to prevent security exceptions. This change ensures that invalid or malformed attributes are handled properly, enhancing the robustness and security of the library.

Before you push a pull request, review this list:

  • Read the contribution guidelines for this project.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge.

@garydgregory
Copy link
Member

Hello @Shivam7-1

You'll need to add a unit test that fails without the changes to 'main'. It looks like the indentation is messed up.

Ty.

@Shivam7-1
Copy link
Author

Hii @garydgregory Thanks for response done this

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

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

@Shivam7-1

You did not follow the instructions in the PR template: Run mvn by itself and fix all errors. The PR title is confusing: The PR doesn't handle any exceptions, it throws exceptions for validation failures.

See my scattered comments as well.

Overall, I'm not sure if this PR is needed: If I apply the test side of the patch, I get ClassFormatExceptions already for the new tests.

Looking at the method, you could see where an NPE could happen but that's not what the tests cause.

*/
package org.apache.bcel.classfile;

import java.security.InvalidParameterException;
Copy link
Member

Choose a reason for hiding this comment

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

This change has nothing to do with JCA or JCE, so java.security.InvalidParameterException is the wrong type. We define ClassFormatException for this very purpose. Examine the reset of the code base for examples.

final String name = constantPool.getConstantUtf8(nameIndex).getBytes();

// Validate name
if (name == null || name.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Reuse StringUtils.isEmpty().


// Call proper constructor, depending on 'tag'
switch (tag) {
// Call proper constructor, depending on 'tag'
Copy link
Member

Choose a reason for hiding this comment

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

The indentation is still messed up, no need to change it.

import org.apache.bcel.classfile.ConstantPool;
import org.junit.jupiter.api.Test;

public class readAttributeTest {
Copy link
Member

Choose a reason for hiding this comment

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

Class name does not follow Java conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants