From f12e0ad4bc54381a4a80fd5ec6249cdd91d0e990 Mon Sep 17 00:00:00 2001 From: LunaTheFoxgirl Date: Fri, 1 Jul 2022 11:10:39 +0200 Subject: [PATCH] parser: sensible psd exporters don't add an extra null terminator --- source/psd/parser.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/psd/parser.d b/source/psd/parser.d index 3aa5e63..d425cf1 100644 --- a/source/psd/parser.d +++ b/source/psd/parser.d @@ -734,7 +734,10 @@ LayerMaskSection* parseLayer(ref File file, ref PSD psd, ulong sectionOffset, ui // If there's a unicode name we may as well use that here. import std.utf : toUTF8; - layer.name = utf16Name.toUTF8[0..$-1]; // strip null character as well + layer.name = utf16Name.toUTF8; + + // Some PSD exporters throw an extra null in there for good measure, yeet it. + if (layer.name[$-1] == '\0') layer.name.length--; // skip possible padding bytes file.skip(length - 4u - characterCountWithoutNull * ushort.sizeof);