HBASE-3585 isLegalFamilyName() can throw ArrayOutOfBoundException

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1327666 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-04-18 20:25:50 +00:00
parent 9ae52f0eab
commit 89a985f28c
2 changed files with 42 additions and 1 deletions

View File

@ -40,6 +40,8 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.io.WritableComparable;
import com.google.common.base.Preconditions;
/** /**
* An HColumnDescriptor contains information about a column family such as the * An HColumnDescriptor contains information about a column family such as the
* number of versions, compression settings, etc. * number of versions, compression settings, etc.
@ -379,12 +381,13 @@ public class HColumnDescriptor implements WritableComparable<HColumnDescriptor>
* @throws IllegalArgumentException If not null and not a legitimate family * @throws IllegalArgumentException If not null and not a legitimate family
* name: i.e. 'printable' and ends in a ':' (Null passes are allowed because * name: i.e. 'printable' and ends in a ':' (Null passes are allowed because
* <code>b</code> can be null when deserializing). Cannot start with a '.' * <code>b</code> can be null when deserializing). Cannot start with a '.'
* either. * either. Also Family can not be an empty value.
*/ */
public static byte [] isLegalFamilyName(final byte [] b) { public static byte [] isLegalFamilyName(final byte [] b) {
if (b == null) { if (b == null) {
return b; return b;
} }
Preconditions.checkArgument(b.length != 0, "Family name can not be empty");
if (b[0] == '.') { if (b[0] == '.') {
throw new IllegalArgumentException("Family names cannot start with a " + throw new IllegalArgumentException("Family names cannot start with a " +
"period: " + Bytes.toString(b)); "period: " + Bytes.toString(b));

View File

@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/** Tests the HColumnDescriptor with appropriate arguments */
public class TestHColumnDescriptor {
@Test
@SuppressWarnings("deprecation")
/** Tests HColumnDescriptor with empty familyName*/
public void testHColumnDescriptorShouldThrowIAEWhenFamiliyNameEmpty()
throws Exception {
try {
new HColumnDescriptor("".getBytes());
} catch (IllegalArgumentException e) {
assertEquals("Family name can not be empty", e.getLocalizedMessage());
}
}
}