darlinghq / darling-dmg

FUSE module for .dmg files (containing an HFS+ filesystem)
http://www.darlinghq.org
GNU General Public License v3.0
273 stars 45 forks source link

HFSCatalogBTree::stat is broken #67

Closed tomkoen closed 6 years ago

tomkoen commented 6 years ago

Recent changes by @jief666 broke the code, newly introduced findHFSPlusCatalogFileOrFolderForParentIdAndName returns invalid data.

for (size_t i = 0; i < elems.size(); i++)
{
    std::string elem = elems[i];

    HFSCatalogNodeID parentID = last ? be(last->folder.folderID) : kHFSRootParentID;
    replaceChars(elem, ':', '/'); // Issue #36: / and : have swapped meaning in HFS+

    // old code
    HFSPlusCatalogKey desiredKey;

    desiredKey.nodeName.length = StringToUnichar(elem, desiredKey.nodeName.string, sizeof(desiredKey.nodeName.string));
    //desiredKey.nodeName.length = ustr.extract(0, ustr.length(), (char*) desiredKey.nodeName.string, "UTF-16BE") / 2;
    desiredKey.nodeName.length = htobe16(desiredKey.nodeName.length);

    desiredKey.parentID = htobe32(parentID);

    leafNode = findLeafNode((Key*)&desiredKey, isCaseSensitive() ? caseSensitiveComparator : caseInsensitiveComparator);
    if (leafNode.isInvalid())
        return -ENOENT;

    last = findRecordForParentAndName(leafNode, parentID, elem); 

    // new
    HFSPlusCatalogFileOrFolder *lastNewBroken = findHFSPlusCatalogFileOrFolderForParentIdAndName(parentID, elem);
tomkoen commented 6 years ago

@jief666, the problem is that after HFSBTreeNode is destroyed, findHFSPlusCatalogFileOrFolderForParentIdAndName returns invalid data

jief666 commented 6 years ago

I'm having a look.

tomkoen commented 6 years ago

One possible workaround is making the variable global

HFSBTreeNode leafNode;
jief666 commented 6 years ago

Yes, yes. I missed that. The funny is that it worked for very big images I'm using to test !

jief666 commented 6 years ago

Global ?? No no, we can do better.

tomkoen commented 6 years ago

The funny is that it worked for very big images I'm using to test !

It could, depends on the compiler...

jief666 commented 6 years ago

I have plenty of RAM, so maybe the new allocation didn't go over the old ones, leaving the memory content intact.

jief666 commented 6 years ago

I'm a big fan of code quality fan ! So great you caught me.

jief666 commented 6 years ago

Here is my solution : #69.

tomkoen commented 6 years ago

Thanks.