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

python: check file pointer when loading trusted setup #401

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

jtraglia
Copy link
Member

@jtraglia jtraglia commented Mar 2, 2024

Fixes: #400

Before:

>>> import ckzg
>>> ckzg.load_trusted_setup("sfsfdsfdsfdsf.json")
[1]    60039 segmentation fault  python

After:

>>> import ckzg
>>> ckzg.load_trusted_setup("sfsfdsfdsfdsf.json")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: error reading trusted setup

Comment on lines 27 to 33
if (load_trusted_setup_file(s, fp) != C_KZG_OK) {
free(s);
fclose(fp);
return PyErr_Format(PyExc_RuntimeError, "error loading trusted setup");
}

fclose(fp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the convention in the other bindings is to do something like:

	fp := C.fopen(cTrustedSetupFile, cMode)
	if fp == nil {
		panic("error reading trusted setup")
	}
	ret := C.load_trusted_setup_file(&settings, fp)
	C.fclose(fp)
	if ret == C.C_KZG_OK {
		loaded = true
	}

where we defer the retval check of load_trusted_setup_file() so that we can unconditionally fclose() once. Should we also adapt this code to that convention?

I think we are also missing an fclose on the error path of the Rust bindings. I can make a new issue for this or handle it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good suggestion. I will make this change. And yes to a new PR for the Rust bindings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pushed at 40f6376

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #402 for the Rust bindings.

@jtraglia jtraglia merged commit 2ab0c21 into ethereum:main Mar 4, 2024
31 checks passed
@jtraglia jtraglia deleted the python-check-file branch March 4, 2024 14:43
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.

Python bindings' load_trusted_setup() segfaults if file does not exist
2 participants