{"record":{"id":"58b60ad5c7270af6","repo":"SixLabors/ImageSharp","slug":"the-iptc-value-exceeds-the-limit-of-maxlength-bytes-for-the","errorCode":null,"errorMessage":"The iptc value exceeds the limit of {maxLength} bytes for the tag {this.Tag}","messagePattern":"The iptc value exceeds the limit of (.+?) bytes for the tag (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs","lineNumber":109,"sourceCode":"        set\n        {\n            if (string.IsNullOrEmpty(value))\n            {\n                this.data = [];\n            }\n            else\n            {\n                int maxLength = this.Tag.MaxLength();\n                byte[] valueBytes;\n                if (this.Strict && value.Length > maxLength)\n                {\n                    string cappedValue = value[..maxLength];\n                    valueBytes = this.encoding.GetBytes(cappedValue);\n\n                    // It is still possible that the bytes of the string exceed the limit.\n                    if (valueBytes.Length > maxLength)\n                    {\n                        throw new ArgumentException($\"The iptc value exceeds the limit of {maxLength} bytes for the tag {this.Tag}\");\n                    }\n                }\n                else\n                {\n                    valueBytes = this.encoding.GetBytes(value);\n                }\n\n                this.data = valueBytes;\n            }\n        }\n    }\n\n    /// <summary>\n    /// Gets the length of the value.\n    /// </summary>\n    public int Length => this.data.Length;\n\n    /// <inheritdoc/>","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs#L91-L127","documentation":"IPTC records cap each field at a fixed byte length (per tag). The IptcValue constructor truncates the string to maxLength characters, but the encoded bytes can still exceed the limit, in which case it throws ArgumentException rather than silently writing a malformed record.","triggerScenarios":"Constructing new IptcValue(encoding, tag, value, strict) where encoding.GetBytes(value) produces more bytes than the tag's maxLength even after string-level truncation — typical with multi-byte encodings (UTF-8/UTF-16) where characters cost more than one byte.","commonSituations":"Long captions or keywords written with UTF-8 non-ASCII characters (accents, CJK) exceeding e.g. a 64-byte limit; using an encoding wider than the record expects.","solutions":["Shorten the value so it fits the tag's byte limit under the chosen encoding","Use a single-byte encoding such as Latin-1 (ISO-8859-1) for the IptcProfile so more characters fit per byte","Truncate the value yourself by encoding incrementally and cutting at a character boundary within maxLength","Catch ArgumentException and skip or log the oversized field when writing metadata in bulk"],"exampleFix":"// before\nnew IptcValue(Encoding.UTF8, IptcTag.Caption, veryLongUnicodeCaption, true);\n// after\nprofile.Update(new IptcValue(Encoding.Latin1, IptcTag.Caption, veryLongUnicodeCaption[..80], true));","handlingStrategy":"validation","validationCode":"int max = 64; // per-tag limit\nbyte[] bytes = Encoding.Latin1.GetBytes(value);\nif (bytes.Length > max) value = Encoding.Latin1.GetString(bytes[..max]);","typeGuard":"static bool FitsTag(string v, Encoding enc, int maxLength) => enc.GetByteCount(v) <= maxLength;","tryCatchPattern":"try { profile.Update(new IptcValue(encoding, tag, value, strict: true)); } catch (ArgumentException ex) { log.Warn(ex, $\"IPTC value too long for {tag}\"); }","preventionTips":["Prefer Latin-1 for IPTC to maximize characters per byte","Check encoding byte length against the tag limit before constructing","Truncate on character boundaries yourself for predictable results"],"tags":["iptc","metadata","payload-too-large","encoding"],"backgroundTag":"payload-too-large","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}