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

Desktop: Fixes #10946: Stop crashing HTML/MD importer when content has link with very long name #10947

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions packages/lib/fs-driver-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default class FsDriverNode extends FsDriverBase {
};
} catch (error) {
if (error.code === 'ENOENT') return null;
if (error.code === 'ENAMETOOLONG') return null;
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this logic should be here. The way stats work is that it either returns the file info, or null if the file doesn't exist. But in this case it exists, except it cannot be processed. So whatever we need to solve it's definitely not here that the fix should be

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The PR name made this more confusing, my bad.

These links are not local resources. The way that importer works is by reading the HTML for links and trying to check if they exist locally or not. When it is a will be a very long link like, or a mailto: to a support address with a template included, for example, fsDriver stat will throw the ENAMETOOLONG.

There isn't any way to file exist because ENAMETOOLONG since it means it is a name longer than the system supports.

Copy link
Owner

Choose a reason for hiding this comment

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

The problem is that a link is being fed to this function, so that should not happen. The current behaviour is correct - it crashes when invalid data is passed to this function. Now the fix is to prevent that data to get there in the first place

throw error;
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/lib/fsDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ describe('fsDriver', () => {
await shim.fsDriver().findUniqueFilename(join(supportDir, 'this-file-does-not-exist.txt'), [join(supportDir, 'some-other-file.txt')]),
).toBe(join(supportDir, 'this-file-does-not-exist.txt'));
});

it('should handle cases where filename is too long in stat', async () => {
const fsDriver = new FsDriverNode();
const filename = `${'12345678'.repeat(32)}9`;

expect(await fsDriver.stat(`./${filename}`)).toBe(null);
});
});
Loading