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

Fix and simplify DirectoryEntry validation #181

Merged

Conversation

jeremy-visionaid
Copy link
Contributor

Ensure both the root and left sibilings are considered when checking for duplicate SIDs.

Also, remove redundant lookups.

@jeremy-visionaid
Copy link
Contributor Author

@ironfede Looks to me like the root should also optionally throw if ValidationExceptionEnabled is set? i.e.

        private void LoadChildren(RBTree bst, IDirectoryEntry de)
        {
            if (de.Child != DirectoryEntry.NOSTREAM)
            {
                IDirectoryEntry child = directoryEntries[de.Child];
                // if (child.StgType != StgType.StgInvalid) // Should actually throw?
                {
                    List<int> levelSIDs = new List<int>();
                    LoadChildren(bst, child, levelSIDs);
                }
            }
        }

WDYT?

Copy link
Owner

@ironfede ironfede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy-visionaid I think thats named used in methods are not 100% representative or their function. For example SiblingIsValid seems to imply it checks for "validity" but it really checks for "existance" of sibling AND do validation. So I think it should be renamed "HasSiblings" and internally throws for validity exception.

@ironfede
Copy link
Owner

ironfede commented Oct 7, 2024

@ironfede Looks to me like the root should also optionally throw if ValidationExceptionEnabled is set? i.e.

        private void LoadChildren(RBTree bst, IDirectoryEntry de)
        {
            if (de.Child != DirectoryEntry.NOSTREAM)
            {
                IDirectoryEntry child = directoryEntries[de.Child];
                // if (child.StgType != StgType.StgInvalid) // Should actually throw?
                {
                    List<int> levelSIDs = new List<int>();
                    LoadChildren(bst, child, levelSIDs);
                }
            }
        }

WDYT?

I think it should throw.

Ensure both the root and left sibilings are considered when checking
for duplicate SIDs.

Also, remove redundant lookups.
@jeremy-visionaid
Copy link
Contributor Author

@jeremy-visionaid I think thats named used in methods are not 100% representative or their function. For example SiblingIsValid seems to imply it checks for "validity" but it really checks for "existance" of sibling AND do validation. So I think it should be renamed "HasSiblings" and internally throws for validity exception.

Hmm, I might take it further and say that the method actually isn't even aware of sibilings - only the caller is, so "HasSiblings" is also arguably misleading. I think perhaps I could just rewrite it to avoid having a boolean return at all.

@jeremy-visionaid
Copy link
Contributor Author

@ironfede I've rewriten to avoid having a bool method, and added another commit on top that fixes the case where an exception was not thrown if the root entry was invalid too.

@ironfede ironfede merged commit d9fbc1f into ironfede:master Oct 7, 2024
1 check passed
@jeremy-visionaid jeremy-visionaid deleted the fix-duplicate-sid-check branch October 16, 2024 03:55
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

Successfully merging this pull request may close these issues.

2 participants