Skip to content
GoogleGHSA-724w-62fm-c94c

LibRaw: Out of bounds write in LibRaw::sonyParseSR2

MediumPublished Aug 14, 2024

### Summary Memory corruption can be achieved by parsing a SR2 file containing a Image File Directory (IFD) with more than 64 TIFFs of specific types. ### Severity Moderate - The values written out of bounds are `unsigned short` read from the input and written as `float`. The `libraw_data_t` struct - in which the overflow manifests - cannot be overrun to target adjacent objects, because the maximum number of entries is 1000 and the remaining size of the struct is greater. However, an attacker could exploit the vulnerability to target adjacent struct fields and achieve second-order memory corruption. ### Proof of Concept 1. Compile LibRaw following the instructions on https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/INSTALL 2. Run the `bin/simple_dcraw` sample binary: bin/simple_dcraw [poc.sr2.bin](https://github.com/google/security-research/blob/master/pocs/LibRaw/poc.sr2.bin) ### Further Analysis LibRaw supports SR2 files, a proprietary binary format developed by Sony to encode RAW pictures. The SR2 container directory is identified by TIFF tag `0xc634` and contains the details for the encrypted TIFF entries, such as the length and the key necessa...

GitHub advisory

Affected versions

PackageAffectedFixed in
LibRaw
Product
all versionsNo fix yet
Details and references

### Summary Memory corruption can be achieved by parsing a SR2 file containing a Image File Directory (IFD) with more than 64 TIFFs of specific types. ### Severity Moderate - The values written out of bounds are `unsigned short` read from the input and written as `float`. The `libraw_data_t` struct - in which the overflow manifests - cannot be overrun to target adjacent objects, because the maximum number of entries is 1000 and the remaining size of the struct is greater. However, an attacker could exploit the vulnerability to target adjacent struct fields and achieve second-order memory corruption. ### Proof of Concept 1. Compile LibRaw following the instructions on https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/INSTALL 2. Run the `bin/simple_dcraw` sample binary: bin/simple_dcraw [poc.sr2.bin](https://github.com/google/security-research/blob/master/pocs/LibRaw/poc.sr2.bin) ### Further Analysis LibRaw supports SR2 files, a proprietary binary format developed by Sony to encode RAW pictures. The SR2 container directory is identified by TIFF tag `0xc634` and contains the details for the encrypted TIFF entries, such as the length and the key necessary to decrypt the nested content. The entrypoint is `LibRaw::open_buffer`, which internally calls `LibRaw::identify`. There are two paths to reach `LibRaw::parseSonySR2`, both of these are via `LibRaw::parse_tiff_ifd`, called in the “identify” stage. Taking one as example, the nested directory is decrypted on https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/src/metadata/tiff.cpp#L1669 and the underlying TIFF entries are handled by `LibRaw::sonyParseSR2`, called immediately after. The first two bytes represent the number of entries and the remaining bytes represent the nested TIFF entries themselves. The issue can be triggered via two different sets of TIFF tags, handled on https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/src/metadata/sony.cpp#L2209 or on https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/src/metadata/sony.cpp#L2222. The first out of bounds value is limited to the `Sony_SR2_wb_list1` entries higher than 255, while the 4 values after come from the input. It is possible to write out of `icWBCCTC` (alias of `imgdata.color.WBCT_Coeffs`) bounds, as it can only store up to 64 entries (https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/libraw/libraw_types.h#L796), while LibRaw allows up to 1000 (https://github.com/LibRaw/LibRaw/blob/158e635e5e80a95dfa402b0a79a7167922c1d4ec/src/metadata/sony.cpp#L2129). ### Timeline **Date reported**: 05/24/2024 **Date fixed**: 05/25/2024 **Date disclosed**: 07/15/2024

Severity from
GitHub (reviewed advisory)

More Google advisories

All Google
Advisory
Lightdash - Stored Cross-Site Scripting
High8.7Aug 29, 2024
Lightdash - Server-Side Request Forgery Session Takeover
High7.3Aug 29, 2024
Open Broadcaster Software (OBS): Heap Overflow Vulnerability
HighAug 19, 2024
TurboMeeting: Post-Authentication Command Injection
High7.2Jul 24, 2024
TurboMeeting: Insecure Password Reset Mechanism
High8.1Jul 24, 2024
TurboMeeting: Boolean-based SQL Injection
Critical9.8Jul 24, 2024

Critical advisories by email

Wednesdays: the week’s critical and high advisories in the AI and data stack, with the fixed versions. Only in weeks that have some.

Double opt-in. Unsubscribe any time.