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

wip: item API suggestions #1027

Closed
wants to merge 7 commits into from

Conversation

bradh
Copy link
Contributor

@bradh bradh commented Nov 4, 2023

The unit test currently fails - see #1002 (comment)

@@ -32,30 +32,30 @@

// ------------------------- reading -------------------------

int heif_context_get_number_of_items(const struct heif_context* ctx)
size_t heif_context_get_number_of_items(const struct heif_context* ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to avoid size_t as much as possible in the interface because that one bit of extra range is not needed here and size_t makes detecting errors much more complicated:
See Scott Meyer

I'm probably fine with size_t when specifying the size of memory areas that may be so large to hit the 2GB boundary on 32bit systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I agree with the analysis. Even in the quoted article, there are plenty of other cases where signed int won't save you (e.g. the off-by-one case).

Internally we're just casting this to size_t anyway, and a common case is to pass in the std::vector size, so I'm casting to int to match the API, then its being cast back...

Possibly we can use size_t and then just check the number isn't greater than some limit, similar to the way we do security checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To get this moving, I've removed the size_t changes.

The unit test still fails.

@@ -216,6 +216,7 @@ struct heif_error heif_context_add_item(struct heif_context* ctx,

if (result && out_item_id) {
*out_item_id = result.value;
ctx->context->get_heif_file()->set_primary_item_id(*out_item_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

But that will overwrite any other primary item id that was set before whenever a new item is added, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

And only if out_item_id is not NULL, which is quite unexpected.

@farindk
Copy link
Contributor

farindk commented Nov 12, 2023

The core issue is probably that libheif was designed to write standard image files and not to build arbitrary files (like your new test) from scratch. This probably has to be refactored from the ground up to get a clean solution.
The new add-item interfaces are ok for adding additional boxes to image files, but one cannot expect yet to build files from scratch.

@bradh
Copy link
Contributor Author

bradh commented Nov 12, 2023

The core issue is probably that libheif was designed to write standard image files and not to build arbitrary files (like your new test) from scratch. This probably has to be refactored from the ground up to get a clean solution. The new add-item interfaces are ok for adding additional boxes to image files, but one cannot expect yet to build files from scratch.

I think that is a valid design choice. Will close this.

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.

2 participants