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

Make XMP SDK code match scanf/printf format strings and types. #2671

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mandree
Copy link
Contributor

@mandree mandree commented Jul 1, 2023

No description provided.

@ghost
Copy link

ghost commented Jul 1, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@codecov
Copy link

codecov bot commented Jul 1, 2023

Codecov Report

Merging #2671 (7ef6c3e) into main (9215f74) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #2671   +/-   ##
=======================================
  Coverage   63.92%   63.92%           
=======================================
  Files         103      103           
  Lines       22305    22305           
  Branches    10795    10795           
=======================================
  Hits        14258    14258           
  Misses       5826     5826           
  Partials     2221     2221           

The numerical OutProc*(num) macros fill in their arguments via
snprintf's "..." varargs part, and the type at the use site depends on
the passed-in types.  This might cause wrong types on the stack that
cause undefined behavior in the snprintf() function, and reading past
memory, outputting garbage.

static_cast<> the macro arguments to the types matching the format
string, to get the expected type width on the stack.
This function uses sscanf() with "%lld" or "%llx" to
parse a string to an integer. However, nothing guarantees
that sizeof(XMP_Int64) == sizeof(long long); the latter
is what sscanf will fill with either of these format strings,
to avoid memory corruption.

Use a long long to match the sscanf size, and let the return statement
cast it to XMP_Int64.
@mandree mandree force-pushed the mandree-fix-xmp-types-formats branch from 9f8dd8c to 7ef6c3e Compare July 1, 2023 21:59
@kmilos
Copy link
Collaborator

kmilos commented Jul 2, 2023

Thanks, but I'd rather we bumped the SDK itself first before pouring developer time into the old version...

@mandree
Copy link
Contributor Author

mandree commented Jul 2, 2023

@kmilos

Thanks, but I'd rather we bumped the SDK itself first before pouring developer time into the old version...

Of course. The thing is I needed to do something on FreeBSD (which is a multi-arch distribution) and I did not want those fixes to get lost in the rubble, but we can turn them into bug reports instead. I am too remote from this Adobe XMP SDK stuff to know where to look, in this case, I have a packager's view and am merely a consumer.
(and dealing with the → 0.28 upgrade issues in FreeBSD, https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272311 ) and this was by-catch.

@kevinbackhouse
Copy link
Collaborator

The last time I looked at https://github.com/adobe/XMP-Toolkit-SDK, I couldn't figure out how to build it. This issue has some context: #1810. It would be great if somebody could figure out how to include it as a dependency rather than having a copy of it in our own repo.

@kmilos
Copy link
Collaborator

kmilos commented Jul 3, 2023

It would be great if somebody could figure out how to include it as a dependency rather than having a copy of it in our own repo.

Yep. In the meantime, I suggest @mandree perhaps handles this as a local packaging patch, or downgrade these to warnings - they don't throw errors on other platforms AFAIK...

@mandree
Copy link
Contributor Author

mandree commented Jul 3, 2023

Oh, no worries about keeping them as packaging patches in the FreeBSD ports collection, we will do that -- but when the type widths of varargs arguments and format strings do not match, crashes and corruptions of stack or heap and of unrelated variables can happen, especially for the *scanf() family of functions. These are very hard to find issues, because usually the crash site or malfunction site can not be traced back to the actual bug site easily -- and a format string type warning from any system is reason to fix the types once and for all. You really do not want to leave this unfixed.

You have been warned.

See the inttypes.h documentation, because since C99, there are fixed-width integer format strings, see

--however I would not bet anything valuable on their portability outside the well-maintained Unix/Linux systems. Although long long is C99 or some local extension, strictly speaking.

Final word, do as you please, but until the day a revised and bugfixed Adobe XMP SDK can safely be kept separate (external), consider fixing the copy in exiv2 in the interim, however useless that may seem. Remember that the absence of a warning, or haphazardly well-behaved code does not mean the absence of a bug. The next compiler version changes layout and then boom. I've seen that happen too many times in the 30+ years that I've been around C code.

@mandree
Copy link
Contributor Author

mandree commented Jul 3, 2023

Reviewing #1810 comments, I suggest to fix those issues locally in the copy, if Adobe seem to have abandoned the XMP SDK.

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.

None yet

3 participants