Skip to content

Commit

Permalink
fix: Corrupting classes where an attribute's name is the last CP index
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed May 20, 2021
1 parent da09ded commit f910eb5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>me.coley</groupId>
<artifactId>cafedude</artifactId>
<url>https://github.com/Col-E/CAFED00D/</url>
<version>1.7.0</version>
<version>1.7.1</version>
<name>CAFED00D</name>

<properties>
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/me/coley/cafedude/ConstPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ public boolean isIndexOfType(int index, Class<? extends ConstPoolEntry> type) {
}

/**
* @return Number of constants in the constant pool. Includes empty entries after wide values <i>(long/double)</i>
* The number of slots in the constant pool, including empty spaces for wide entry padding
* <i>(A mistake even sun regrets)</i>.
* <br>
* Note that even if the pool has a size of {@code 1}
* you should still use {@code 1} as the argument for {@link #get(int)} since the pool is not
* 0-indexed. Instead indices start at 1.
*
* @return Number of constants in the constant pool.
* Includes empty entries after wide values <i>(long/double)</i>
* <br>
* {@code 0} when there are no items.
*/
public int size() {
if (last == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static <T extends Attribute> boolean isValid(ConstPool cp, T attribute) {
private <T extends Attribute> boolean isValid(T attribute) {
// Check name index
int maxCpIndex = pool.size();
if (attribute.getNameIndex() >= maxCpIndex)
if (attribute.getNameIndex() > maxCpIndex)
return false;
// Check indices match certain types (key=cp_index, value=mask of allowed cp_tags)
String name = pool.getUtf(attribute.getNameIndex());
Expand Down

0 comments on commit f910eb5

Please sign in to comment.