diff --git a/CHANGES.md b/CHANGES.md index 11b4eca758..faa04b54fb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ Features Bug Fixes --------- +* Avoid truncating final character when macOS getXAttr reads a non-null-terminated xattr, e.g. an xattr created using `xattr -w user.sample 1 myfile.txt`. +* Avoid including null termination as part of macOS setXAttr. * [#1091](https://github.com/java-native-access/jna/issues/1091): Check target number to be greater than zero, before calling `Structure#toArray` in `c.s.j.p.win32.Netapi32Util` - [@trevormagg](https://github.com/trevormaggs), [@matthiasblaesing](https://github.com/matthiasblaesing). Release 5.3.1 diff --git a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java index 09085d8d47..05371d206a 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java @@ -67,12 +67,12 @@ public static String getXAttr(String path, String name) { if (valueLength < 0) return null; - return decodeString(valueBuffer.getByteBuffer(0, valueLength - 1)); + return decodeString(valueBuffer.getByteBuffer(0, valueLength)); } public static int setXAttr(String path, String name, String value) { Memory valueBuffer = encodeString(value); - return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size(), 0, 0); + return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size() - 1, 0, 0); } public static int removeXAttr(String path, String name) {