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

Segmentation fault with large indent #501

Closed
JustAnotherArchivist opened this issue Feb 6, 2022 · 3 comments · Fixed by #519
Closed

Segmentation fault with large indent #501

JustAnotherArchivist opened this issue Feb 6, 2022 · 3 comments · Fixed by #519

Comments

@JustAnotherArchivist
Copy link
Collaborator

What did you do?

python3 -c 'import ujson; print(ujson.encode({"a": True}, indent=65539))' >/dev/null

This is the smallest value that triggers the segfault on my machine with this build of ujson. I'm sure it's no coincidence that it's slightly larger than 64 KiB.

What did you expect to happen?

Properly (if poorly) formatted output

What actually happened?

SIGSEGV

What versions are you using?

  • OS: Debian Sid
  • Python: 3.10.1
  • UltraJSON: 316d384

I think the reason might lie in the fact that the Buffer_Reserve call in encode does not appear to account for indentation at all. I wouldn't be surprised if other things could also trigger buffer overruns in certain conditions, e.g. the absence of JSON_NO_EXTRA_WHITESPACE causing the insertion of extra spaces.

#334 and #402 might be symptoms of the same underlying bug. Note that they both use indentation.

@bwoodsend
Copy link
Collaborator

We're aware of this one. I'm supposed to be in the process of fixing it (although I haven't been particularly proactive about it).

@opalmeira
Copy link

Hello!
Any updates on this issue?
I'm having this problem too, but with indent = 1 in a larger file.

df1.to_json("/path/to/output/file1.json", indent = 1)
df2.to_json("/path/to/output/file2.json", indent = 1)

file1 is 78M - no Segmentation fault
file2 is 81M - Segmentation fault (core dumped)
If I run file2 without indent, I have no problem

Python 3.10.4
Ubuntu 22.04

I would appreciate if anybody can help me solve this problem.
Thank you!

@bwoodsend
Copy link
Collaborator

I'm guessing that you're using pandas? They've got their own copy of ujson so you should take this up with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants