Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Java class pattern error[E0004]: Type error, Array expanded past end of data. #120

Open
Guigumua opened this issue Jun 6, 2023 · 14 comments

Comments

@Guigumua
Copy link
Contributor

Guigumua commented Jun 6, 2023

attribute_name_index value show error[E0004]: Type error, Array expanded past end of data.

image

Reappear

Java source code:

class Test {
  private String a = "a";
  private String b = "b";
  private String c = "c";
  private String d = "d";
  private String e = "e";
  private String f = "f";
  private String g = "g";
  private String h = "h";
  private String i = "i";
  private String j = "j";
  private String k = "k";
  private String l = "l";
  private String m = "m";
  private String n = "n";
  private String o = "o";
  private String p = "p";
  private String q = "q";
  private String r = "r";
  private String s = "s";
  private String t = "t";
  private String u = "u";
  private String v = "v";
  private String w = "w";
  private String x = "x";
  private String y = "y";
  private String z = "z";
  private String aa = "aa";
  private String ab = "ab";
  private String ac = "ac";
  private String ad = "ad";
  private String ae = "ae";
  private String af = "af";
  private String ag = "ag";
  private String ah = "ah";
  private String ai = "ai";
  private String aj = "aj";
  private String ak = "ak";
  private String al = "al";
  private String am = "am";
  private String an = "an";
  private String ao = "ao";
  private String ap = "ap";
  private String aq = "aq";
  private String ar = "ar";
  private String as = "as";
  private String at = "at";
  private String au = "au";
  private String av = "av";
  private String aw = "aw";
  private String ax = "ax";
  private String ay = "ay";
  private String az = "az";
  private String ba = "ba";
  private String bb = "bb";
  private String bc = "bc";
  private String bd = "bd";
  private String be = "be";
  private String bf = "bf";
  private String bg = "bg";

  public static void main(String[] args) throws Exception {
    System.out.println("Hello World!");
    System.out.println("Hello World");
  }
  
}

error occurred in file.methods[n].attributes[n].attribute_name_index and file.methods[n].attributes[n].atrributes[n].attribute_name_index :

image

if delete a field, error occurred in file.methods[n].attributes[n].atrributes[n].attribute_name_index:

image

if delete two field, no orror:

image

I don't know if this error is related to the number of fields or the constant pool size, I also got this error with another class that has multiple methods but only one field.

@paxcut
Copy link
Contributor

paxcut commented Jun 6, 2023

can you provide the binary file to test the pattern or instructions on how to generate fro, the source code?

@Guigumua
Copy link
Contributor Author

Guigumua commented Jun 6, 2023

can you provide the binary file to test the pattern or instructions on how to generate fro, the source code?

https://github.com/Guigumua/file/blob/main/Test.class

If you can't reproduce the problem, you can try adding more fields, source code in the same folder

@pakahenepy
Copy link

any fix for this? running into a similar problem

@paxcut
Copy link
Contributor

paxcut commented Aug 9, 2024

The file provided doesn't generate error messages and the pattern covers the entire file. I'm not a java person so adding more fields doesn't help. If you have a file that is generating incorrect results when running the java class pattern I would need a copy to be able to debug the process and find out why the errors occur. This error is indicative of a flaw in the pattern that often manifests itself as a large array size or an address bigger than what the input file can have

@pakahenepy
Copy link

The file provided doesn't generate error messages and the pattern covers the entire file. I'm not a java person so adding more fields doesn't help. If you have a file that is generating incorrect results when running the java class pattern I would need a copy to be able to debug the process and find out why the errors occur. This error is indicative of a flaw in the pattern that often manifests itself as a large array size or an address bigger than what the input file can have

I can share the file I'm running into the error with it you'd like

@paxcut
Copy link
Contributor

paxcut commented Aug 9, 2024

yes please

@pakahenepy
Copy link

pakahenepy commented Aug 9, 2024

the file uses the PE hexpat but its the same error and i couldnt find anything else related, note, it only errors if i have "check for symbols" enabled"
https://drive.google.com/file/d/1-Cly7aMe0ZQBVTS5piecQTN0AS6pQOpG/view?usp=sharing

@paxcut
Copy link
Contributor

paxcut commented Aug 9, 2024

Finding problems in pe pattern and fixing them is not going to help fix problems in java class patterns. If both are giving the same error the reasons can and generally are completely different for each case. So for this issue please post information about the java class pattern and the "Array expanded past end of file" error.

The link provided hasn't been created properly because it is pointing to github instead of drives.google. I had to copy the link and paste it to download the executable but when I ran the pe pattern it didn't result in an error about reading past the end of the file.
The actual error was

E: runtime error: Pattern count exceeded set limit of '131072'.

E: If this is intended, try increasing the limit using '#pragma pattern_limit <new_limit>'.

The line after the error tells you how to fix it.

@pakahenepy
Copy link

Finding problems in pe pattern and fixing them is not going to help fix problems in java class patterns. If both are giving the same error the reasons can and generally are completely different for each case. So for this issue please post information about the java class pattern and the "Array expanded past end of file" error.

The link provided hasn't been created properly because it is pointing to github instead of drives.google. I had to copy the link and paste it to download the executable but when I ran the pe pattern it didn't result in an error about reading past the end of the file.
The actual error was

E: runtime error: Pattern count exceeded set limit of '131072'.

E: If this is intended, try increasing the limit using '#pragma pattern_limit <new_limit>'.

The line after the error tells you how to fix it.

I'm only trying to fix the pe problem, i put the post here because I didn't know where else to put it, also I already fixed the pattern limit by manually increasing the cap.

@paxcut
Copy link
Contributor

paxcut commented Aug 9, 2024

The place to post problems with the pe pattern would be a new issue created that describes the error and to to reproduce it. After fixing the limit of patterns so that it is bigger than what the file needs the pe pattern runs to completion without any errors and the pattern covers the entire file. Are you seeing some error instead? Maybe post you ImHex version because that could be caused by a pe pattern that hasn't been patched but it is hard to tell for sure without more info.

@pakahenepy
Copy link

im running the 3.6.0 beta, i tried running the last stable build and the same error happened, make sure you have "check for symbols" enabled in the settings, if you do not have this on then the error doesnt appear, but many sections are either unlabled or are considered "freeform".

@paxcut
Copy link
Contributor

paxcut commented Aug 9, 2024

The error is that the file has no symbols but the code tries to create a StringTable array of size 1 and because there are no symbols then the address of symbolTable is zero and so is its size so the StringTable array is placed at zero where it picks a huge value for StringTable size causing the error. This can be fixed by changing line 1215 to read

StringTable stringTable[sizeof(symbolTable)>0] @ addressof(symbolTable) + sizeof(symbolTable);

so that the size of the StringTable array is one only if there are symbols and zero otherwise.

@pakahenepy
Copy link

fixed, thank you!

@paxcut
Copy link
Contributor

paxcut commented Aug 10, 2024

It looks like you duplicated the pe pattern or maybe you wrote over the one that comes with ImHex. While that will work just fine for now, when you update ImHex that code may be overwritten. The change will be added to a pull request which if it is merged will become available directly on new downloads. In the meantime all you needed to do is turn off the symbol search. It is an optional feature that is currently broken.

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

No branches or pull requests

3 participants