unipdf-cli icon indicating copy to clipboard operation
unipdf-cli copied to clipboard

Invalid Cross-Device Link

Open deon-gracias opened this issue 1 year ago • 9 comments

While trying to run a split on a pdf and writing it to the same area. I get this error of Invalid Cross-Device.

Going through the source code and messing I came to know it's cause of the os.Rename done in pkg/pdf/utils.go specifically in writePdf function on line 83.

The fix I found for it was just simply copying the file to the TEMP_DIR but then there's an issue that we cannot delete the file from TEMP_DIR when it is /tmp due to access rights I think.

image

deon-gracias avatar Sep 21 '24 17:09 deon-gracias

Hi @deon-gracias do you modify the unipdf-cli code?

I tried but can't reproduce the issue.

alip@alips unipdf % go run main.go split ~/unipdf-security-report-3.pdf ~/unipdf-security-report-3.pdf 1
Successfully split file ~/unipdf-security-report-3.pdf
Output file saved to ~/unipdf-security-report-3.pdf
alip@alips unipdf % 

sampila avatar Sep 21 '24 18:09 sampila

No I haven't, but I still re-cloned the repository and tried again. This was the result.

image

I also checked if I have some other /tmp/unipdf_sample.pdf in my file doing a ls grep but nothing showed up

image

deon-gracias avatar Sep 21 '24 18:09 deon-gracias

Could you share your pdf file?

Hard to debug if unable to reproduce the issue

sampila avatar Sep 21 '24 18:09 sampila

I'm sure its not the pdf that is the issue but here you go. I'll also look into some solutions, other than just copying the file to the /tmp dir

sample.pdf

deon-gracias avatar Sep 21 '24 18:09 deon-gracias

I'm sure its not the pdf that is the issue but here you go. I'll also look into some solutions, other than just copying the file to the /tmp dir

sample.pdf

Yes, I am unable to reproduce it. Screenshot 2024-09-22 at 02 07 21

sampila avatar Sep 21 '24 19:09 sampila

I got it to work after changing the temp file location in the writePDF().

image

image

The issue is that by default on /tmp which is the problem. Creating a folder in the users /home/$USER dir works fine.

deon-gracias avatar Sep 22 '24 08:09 deon-gracias

I got it to work after changing the temp file location in the writePDF().

image

image

The issue is that by default on /tmp which is the problem. Creating a folder in the users /home/$USER dir works fine.

Normally, it should call the temporary directory using os.TempDir() like here https://github.com/unidoc/unipdf-cli/blob/9dfe4f14cd22cc49c7a406356416128273803237/pkg/pdf/utils.go#L82

sampila avatar Sep 23 '24 12:09 sampila

Yes and the os.TempDir() for me returns /tmp path

deon-gracias avatar Sep 24 '24 21:09 deon-gracias

Pretty strange, can try with other pdf? seems file permission issue to me, as I can't reproduce the issue also here.

sampila avatar Sep 24 '24 21:09 sampila

Yea the only thing I can think about is / is in root so its not allowing it to rename the file created in /tmp.

deon-gracias avatar Sep 26 '24 12:09 deon-gracias

So, I am closing this issue for now, as I can't reproduce it on my end.

Feel free to re-open the issue if there's a way to reproduce the issue and we will re-open this also if we found way to reproduce and confirm this issue.

sampila avatar Sep 26 '24 12:09 sampila