HDFS-14172. Avoid NPE when SectionName#fromString returns null. Contributed by Xiang Li.

This commit is contained in:
Yiqun Lin 2019-02-08 20:51:30 +08:00
parent 394a9f7d5c
commit 177131793a
4 changed files with 22 additions and 5 deletions

View File

@ -241,8 +241,11 @@ public final class FSImageFormatProtobuf {
summary.getCodec(), in);
String n = s.getName();
switch (SectionName.fromString(n)) {
SectionName sectionName = SectionName.fromString(n);
if (sectionName == null) {
throw new IOException("Unrecognized section " + n);
}
switch (sectionName) {
case NS_INFO:
loadNameSystemSection(in);
break;

View File

@ -156,7 +156,13 @@ class FSImageLoader {
LOG.debug("Loading section " + s.getName() + " length: " + s.getLength
());
}
switch (FSImageFormatProtobuf.SectionName.fromString(s.getName())) {
FSImageFormatProtobuf.SectionName sectionName
= FSImageFormatProtobuf.SectionName.fromString(s.getName());
if (sectionName == null) {
throw new IOException("Unrecognized section " + s.getName());
}
switch (sectionName) {
case STRING_TABLE:
stringTable = loadStringTable(is);
break;

View File

@ -594,7 +594,11 @@ abstract class PBImageTextWriter implements Closeable {
is = FSImageUtil.wrapInputStreamForCompression(conf,
summary.getCodec(), new BufferedInputStream(new LimitInputStream(
fin, section.getLength())));
switch (SectionName.fromString(section.getName())) {
SectionName sectionName = SectionName.fromString(section.getName());
if (sectionName == null) {
throw new IOException("Unrecognized section " + section.getName());
}
switch (sectionName) {
case STRING_TABLE:
LOG.info("Loading string table");
stringTable = FSImageLoader.loadStringTable(is);

View File

@ -326,7 +326,11 @@ public final class PBImageXmlWriter {
summary.getCodec(), new BufferedInputStream(new LimitInputStream(
fin, s.getLength())));
switch (SectionName.fromString(s.getName())) {
SectionName sectionName = SectionName.fromString(s.getName());
if (sectionName == null) {
throw new IOException("Unrecognized section " + s.getName());
}
switch (sectionName) {
case NS_INFO:
dumpNameSection(is);
break;