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

TClasses throws Exception #1

Open
LokiMidgard opened this issue Jun 10, 2012 · 3 comments
Open

TClasses throws Exception #1

LokiMidgard opened this issue Jun 10, 2012 · 3 comments

Comments

@LokiMidgard
Copy link

The Constructor throws a lot of Exceptions.

I think the Problem is that the if always returns true. If Common.ReadWord(Reader) returns 0, this Value will be decremented by one. That leads to the maximum value of Uint. That is greater than 0.

      public TClasses(BinaryReader Reader, TConstantPool ConstantPool)
        {
            InnerClassInfoIndex = 0;
            InnerClassInfo = null;
            OuterClassInfoIndex = 0;
            ;
            OuterClassInfo = null;
            InnerNameIndex = 0;
            ;
            InnerName = null;
            InnerClassAccessFlags = 0;
            ;

            try
            {
                InnerClassInfoIndex = Common.ReadWord(Reader);
                InnerClassInfoIndex--;
                OuterClassInfoIndex = Common.ReadWord(Reader);
                OuterClassInfoIndex--;
                InnerNameIndex = Common.ReadWord(Reader);
                InnerNameIndex--;
                InnerClassAccessFlags = Common.ReadWord(Reader);

                // resolve references
                if (InnerNameIndex >= 0) // Always true because ushort has no value below 0
                {
                    InnerName = (ConstantUtf8Info)ConstantPool.Item(InnerNameIndex);
                    InnerName.References++; // Check for Null to avoid Exceptions
                }
                if (InnerNameIndex >= 0) // Always true because ushort has no value below 0
                {
                    InnerClassInfo = (ConstantClassInfo)ConstantPool.Item(InnerClassInfoIndex);
                    InnerClassInfo.References++;// Check for Null to avoid Exceptions
                }
                if (InnerNameIndex >= 0) // Always true because ushort has no value below 0
                {
                    OuterClassInfo = (ConstantClassInfo)ConstantPool.Item(OuterClassInfoIndex);
                    OuterClassInfo.References++;// Check for Null to avoid Exceptions
                }
            }
            catch (Exception e)
            {
                // do nothing
            }
        }
@fileoffset
Copy link
Owner

Thanks for reporting this bug, you are most correct.

Do you have any .class files which I can use to test the fix for this?

@LokiMidgard
Copy link
Author

I'm sorry, I can't find the project in my backups.
I can only say that it happened unsing the Jar of this Project: http://helden-software.de/ (homepage) http://download.helden-software.de/download3.php (download)

@fileoffset
Copy link
Owner

Cool thanks, I'm looking to change the code structure to fix this - it seems to be endemic. I'm going to try and add some automated tests as well.

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

2 participants