HDFS-8963. Fix incorrect sign extension of xattr length in HDFS-8900. (Colin Patrick McCabe via yliu)

This commit is contained in:
yliu 2015-08-28 10:54:55 +08:00
parent 035ed26147
commit e166c038c0
3 changed files with 25 additions and 4 deletions

View File

@ -1243,6 +1243,9 @@ Release 2.8.0 - UNRELEASED
HDFS-8969. Clean up findbugs warnings for HDFS-8823 and HDFS-8932.
(Anu Engineer via wheat9)
HDFS-8963. Fix incorrect sign extension of xattr length in HDFS-8900.
(Colin Patrick McCabe via yliu)
Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -61,12 +61,15 @@ static List<XAttr> toXAttrs(byte[] attrs) {
for (int i = 0; i < attrs.length;) {
XAttr.Builder builder = new XAttr.Builder();
// big-endian
int v = Ints.fromBytes(attrs[i++], attrs[i++], attrs[i++], attrs[i++]);
int v = Ints.fromBytes(attrs[i], attrs[i + 1],
attrs[i + 2], attrs[i + 3]);
i += 4;
int ns = (v >> XATTR_NAMESPACE_OFFSET) & XATTR_NAMESPACE_MASK;
int nid = v & XATTR_NAME_MASK;
builder.setNameSpace(XATTR_NAMESPACE_VALUES[ns]);
builder.setName(XAttrStorage.getName(nid));
int vlen = (attrs[i++] << 8) | attrs[i++];
int vlen = ((0xff & attrs[i]) << 8) | (0xff & attrs[i + 1]);
i += 2;
if (vlen > 0) {
byte[] value = new byte[vlen];
System.arraycopy(attrs, i, value, 0, vlen);
@ -94,12 +97,15 @@ static XAttr getXAttr(byte[] attrs, String prefixedName) {
XAttr xAttr = XAttrHelper.buildXAttr(prefixedName);
for (int i = 0; i < attrs.length;) {
// big-endian
int v = Ints.fromBytes(attrs[i++], attrs[i++], attrs[i++], attrs[i++]);
int v = Ints.fromBytes(attrs[i], attrs[i + 1],
attrs[i + 2], attrs[i + 3]);
i += 4;
int ns = (v >> XATTR_NAMESPACE_OFFSET) & XATTR_NAMESPACE_MASK;
int nid = v & XATTR_NAME_MASK;
XAttr.NameSpace namespace = XATTR_NAMESPACE_VALUES[ns];
String name = XAttrStorage.getName(nid);
int vlen = (attrs[i++] << 8) | attrs[i++];
int vlen = ((0xff & attrs[i]) << 8) | (0xff & attrs[i + 1]);
i += 2;
if (xAttr.getNameSpace() == namespace &&
xAttr.getName().equals(name)) {
if (vlen > 0) {

View File

@ -43,6 +43,14 @@ public class TestXAttrFeature {
static final String name7 = "raw.a7";
static final byte[] value7 = {0x011, 0x012, 0x013};
static final String name8 = "user.a8";
static final String bigXattrKey = "user.big.xattr.key";
static final byte[] bigXattrValue = new byte[128];
static {
for (int i = 0; i < bigXattrValue.length; i++) {
bigXattrValue[i] = (byte) (i & 0xff);
}
}
static byte[] randomBytes(int len) {
Random rand = new Random();
@ -74,12 +82,14 @@ public void testXAttrFeature() throws Exception {
XAttr a5 = XAttrHelper.buildXAttr(name5, value5);
XAttr a6 = XAttrHelper.buildXAttr(name6, value6);
XAttr a7 = XAttrHelper.buildXAttr(name7, value7);
XAttr bigXattr = XAttrHelper.buildXAttr(bigXattrKey, bigXattrValue);
xAttrs.add(a2);
xAttrs.add(a3);
xAttrs.add(a4);
xAttrs.add(a5);
xAttrs.add(a6);
xAttrs.add(a7);
xAttrs.add(bigXattr);
feature = new XAttrFeature(xAttrs);
XAttr r2 = feature.getXAttr(name2);
@ -94,6 +104,8 @@ public void testXAttrFeature() throws Exception {
assertTrue(a6.equals(r6));
XAttr r7 = feature.getXAttr(name7);
assertTrue(a7.equals(r7));
XAttr rBigXattr = feature.getXAttr(bigXattrKey);
assertTrue(bigXattr.equals(rBigXattr));
List<XAttr> rs = feature.getXAttrs();
assertEquals(rs.size(), xAttrs.size());
for (int i = 0; i < rs.size(); i++) {