View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.bcel;
20  
21  import static org.junit.jupiter.api.Assertions.assertThrows;
22  
23  import java.io.File;
24  import java.io.FileInputStream;
25  
26  import org.apache.bcel.classfile.ClassFormatException;
27  import org.apache.bcel.classfile.ClassParser;
28  import org.junit.jupiter.api.Test;
29  
30  class OssFuzzTest {
31  
32      @Test
33      void testIssue51980() throws Exception {
34          testOssFuzzReproducer("51980");
35      }
36  
37      @Test
38      void testIssue51989() throws Exception {
39          testOssFuzzReproducer("51989");
40      }
41  
42      @Test
43      void testIssue52168() throws Exception {
44          testOssFuzzReproducer("52168");
45      }
46  
47      @Test
48      void testIssue53543() throws Exception {
49          testOssFuzzReproducer("53543");
50      }
51  
52      /**
53       * The original issue 53544 was a false positive but reviewing that issue did find a valid issue nearby.
54       */
55      @Test
56      void testIssue53544a() throws Exception {
57          testOssFuzzReproducer("53544a");
58      }
59  
60      @Test
61      void testIssue53620() throws Exception {
62          testOssFuzzReproducer("53620");
63      }
64  
65      @Test
66      void testIssue53676() throws Exception {
67          testOssFuzzReproducer("53676");
68      }
69  
70      @Test
71      void testIssue54119() throws Exception {
72          testOssFuzzReproducer("54119");
73      }
74  
75      @Test
76      void testIssue54254() throws Exception {
77          testOssFuzzReproducer("54254");
78      }
79  
80      private void testOssFuzzReproducer(final String issue) throws Exception {
81          // Class names here use non-".class" suffix so that Maven plugins like surefire do not try to read the file and fail the build.
82          final File reproducerFile = new File("target/test-classes/ossfuzz/issue" + issue + "/Test.classx");
83          try (FileInputStream reproducerInputStream = new FileInputStream(reproducerFile)) {
84              final ClassParser cp = new ClassParser(reproducerInputStream, "Test");
85              assertThrows(ClassFormatException.class, () -> cp.parse());
86          }
87      }
88  }