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