Skip to content

Commit a58d8d5

Browse files
committed
Ignore iptc records, which are not application records when reading iptc data
1 parent 9c7ba12 commit a58d8d5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
2121
private const uint MaxStandardDataTagSize = 0x7FFF;
2222

2323
/// <summary>
24-
/// 1:90 Coded Character Set
24+
/// 1:90 Coded Character Set.
2525
/// </summary>
2626
private const byte IptcEnvelopeCodedCharacterSet = 0x5A;
2727

2828
/// <summary>
29-
/// This value marks that UTF-8 encoding is used in application records
29+
/// This value marks that UTF-8 encoding is used in application records.
3030
/// </summary>
3131
private static readonly byte[] CodedCharacterSetUtf8Value = { 0x1B, 0x25, 0x47 };
3232

@@ -255,15 +255,15 @@ public void UpdateData()
255255

256256
if (hasValuesInUtf8)
257257
{
258-
length += 5 + CodedCharacterSetUtf8Value.Length; // additional length for UTF-8 Tag
258+
length += 5 + CodedCharacterSetUtf8Value.Length; // Additional length for UTF-8 Tag.
259259
}
260260

261261
this.Data = new byte[length];
262262
int i = 0;
263263

264264
if (hasValuesInUtf8)
265265
{
266-
// Standard DataSet Tag
266+
// Envelope Record.
267267
this.Data[i++] = IptcTagMarkerByte;
268268
this.Data[i++] = 1; // Envelope
269269
this.Data[i++] = IptcEnvelopeCodedCharacterSet;
@@ -275,7 +275,7 @@ public void UpdateData()
275275

276276
foreach (IptcValue value in this.Values)
277277
{
278-
// Standard DataSet Tag
278+
// Application Record.
279279
// +-----------+----------------+---------------------------------------------------------------------------------+
280280
// | Octet Pos | Name | Description |
281281
// +==========-+================+=================================================================================+
@@ -327,6 +327,7 @@ private void Initialize()
327327
bool isValidRecordNumber = recordNumber is >= 1 and <= 9;
328328
var tag = (IptcTag)this.Data[offset++];
329329
bool isValidEntry = isValidTagMarker && isValidRecordNumber;
330+
bool isApplicationRecord = recordNumber == 0x02;
330331

331332
uint byteCount = BinaryPrimitives.ReadUInt16BigEndian(this.Data.AsSpan(offset, 2));
332333
offset += 2;
@@ -336,7 +337,7 @@ private void Initialize()
336337
break;
337338
}
338339

339-
if (isValidEntry && byteCount > 0 && (offset <= this.Data.Length - byteCount))
340+
if (isValidEntry && isApplicationRecord && byteCount > 0 && (offset <= this.Data.Length - byteCount))
340341
{
341342
byte[] iptcData = new byte[byteCount];
342343
Buffer.BlockCopy(this.Data, offset, iptcData, 0, (int)byteCount);
@@ -348,9 +349,9 @@ private void Initialize()
348349
}
349350

350351
/// <summary>
351-
/// Gets if any value has UTF-8 encoding
352+
/// Gets if any value has UTF-8 encoding.
352353
/// </summary>
353-
/// <returns>true if any value has UTF-8 encoding</returns>
354+
/// <returns>true if any value has UTF-8 encoding.</returns>
354355
private bool HasValuesInUtf8()
355356
{
356357
foreach (IptcValue value in this.values)

0 commit comments

Comments
 (0)