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

asf: fix GUID reading on big endian platforms #2694

Merged
merged 1 commit into from Jul 17, 2023

Conversation

pinotree
Copy link
Contributor

Setting the initial parts (data1_, data2_, data3_) from the bytes directly using memcpy() means that they will be interpreted depending on the platform endianness. For example, the initial 4 bytes of the ASF header are 0x30, 0x26, 0xB2, 0x75, which will be read as 0x3026B275 on big endian platofrms, never matching the actual GUID (0x75B22630), which is always specified in little endian format.

Hence, when reading a GUID from data, make sure to turn the GUID parts to little endian. This fixes the reading of ASF files on big endian platforms.

Fixes commit bed8d3d

@ghost
Copy link

ghost commented Jul 16, 2023

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

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Setting the initial parts (data1_, data2_, data3_) from the bytes
directly using memcpy() means that they will be interpreted depending
on the platform endianness. For example, the initial 4 bytes of the ASF
header are 0x30, 0x26, 0xB2, 0x75, which will be read as 0x3026B275 on
big endian platforms, never matching the actual GUID (0x75B22630), which
is always specified in little endian format.

Hence, when reading a GUID from data, make sure to turn the GUID parts
to little endian. This fixes the reading of ASF files on big endian
platforms.

Fixes commit bed8d3d
@codecov
Copy link

codecov bot commented Jul 16, 2023

Codecov Report

Merging #2694 (235a117) into main (7473b4a) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #2694      +/-   ##
==========================================
- Coverage   63.91%   63.89%   -0.02%     
==========================================
  Files         103      103              
  Lines       22314    22318       +4     
  Branches    10800    10801       +1     
==========================================
  Hits        14261    14261              
- Misses       5828     5831       +3     
- Partials     2225     2226       +1     
Impacted Files Coverage Δ
src/asfvideo.cpp 52.73% <0.00%> (-0.84%) ⬇️

@neheb
Copy link
Collaborator

neheb commented Jul 16, 2023

sounds like this fixes #2597

can you confirm?

@@ -55,6 +55,11 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
memcpy(&data2_, bytes + DWORD, WORD);
memcpy(&data3_, bytes + DWORD + WORD, WORD);
std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin());
if (isBigEndianPlatform()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In other places where I've seen this pattern, a variable gets set to isBigEndianPlatform() and byteSwap gets called as:

    data1_ = byteSwap(data1_, bSwap);
    data2_ = byteSwap(data2_, bSwap);
    data3_ = byteSwap(data3_, bSwap);

@neheb
Copy link
Collaborator

neheb commented Jul 16, 2023

It does fix the linked issue. Just tested.

@pinotree
Copy link
Contributor Author

sounds like this fixes #2597

can you confirm?

I don't have a big-endian 64bit mips system, however the fix worked fine on a s390x system.

@neheb neheb merged commit b826a7d into Exiv2:main Jul 17, 2023
105 checks passed
@neheb
Copy link
Collaborator

neheb commented Jul 17, 2023

@Mergifyio backport 0.28.x

@mergify
Copy link
Contributor

mergify bot commented Jul 17, 2023

backport 0.28.x

✅ Backports have been created

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

2 participants