#vulnerable code 
                                @Override
    protected IIOMetadataNode getStandardChromaNode() {
        IIOMetadataNode chroma = new IIOMetadataNode("Chroma");

        // Handle ColorSpaceType (RGB/CMYK/YCbCr etc)...
        Entry photometricTag = ifd.getEntryById(TIFF.TAG_PHOTOMETRIC_INTERPRETATION);
        int photometricValue = getValueAsInt(photometricTag); // No default for this tag!

        Entry samplesPerPixelTag = ifd.getEntryById(TIFF.TAG_SAMPLES_PER_PIXEL);
        Entry bitsPerSampleTag = ifd.getEntryById(TIFF.TAG_BITS_PER_SAMPLE);
        int numChannelsValue = samplesPerPixelTag != null
                               ? getValueAsInt(samplesPerPixelTag)
                               : bitsPerSampleTag.valueCount();

        IIOMetadataNode colorSpaceType = new IIOMetadataNode("ColorSpaceType");
        chroma.appendChild(colorSpaceType);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_MASK: // It's really a transparency mask/alpha channel, but...
                colorSpaceType.setAttribute("value", "GRAY");
                break;
            case TIFFBaseline.PHOTOMETRIC_RGB:
            case TIFFBaseline.PHOTOMETRIC_PALETTE:
                colorSpaceType.setAttribute("value", "RGB");
                break;
            case TIFFExtension.PHOTOMETRIC_YCBCR:
                colorSpaceType.setAttribute("value", "YCbCr");
                break;
            case TIFFExtension.PHOTOMETRIC_CIELAB:
            case TIFFExtension.PHOTOMETRIC_ICCLAB:
            case TIFFExtension.PHOTOMETRIC_ITULAB:
                colorSpaceType.setAttribute("value", "Lab");
                break;
            case TIFFExtension.PHOTOMETRIC_SEPARATED:
                // TODO: May be CMYK, or something else... Consult InkSet and NumberOfInks!
                if (numChannelsValue == 3) {
                    colorSpaceType.setAttribute("value", "CMY");
                }
                else {
                    colorSpaceType.setAttribute("value", "CMYK");
                }
                break;
            case TIFFCustom.PHOTOMETRIC_LOGL: // ..?
            case TIFFCustom.PHOTOMETRIC_LOGLUV:
                colorSpaceType.setAttribute("value", "Luv");
                break;
            case TIFFCustom.PHOTOMETRIC_CFA:
            case TIFFCustom.PHOTOMETRIC_LINEAR_RAW: // ...or is this RGB?
                colorSpaceType.setAttribute("value", "3CLR");
                break;
            default:
                colorSpaceType.setAttribute("value", Integer.toHexString(numChannelsValue) + "CLR");
                break;
        }

        // NumChannels
        IIOMetadataNode numChannels = new IIOMetadataNode("NumChannels");
        chroma.appendChild(numChannels);
        if (photometricValue == TIFFBaseline.PHOTOMETRIC_PALETTE) {
            numChannels.setAttribute("value", "3");
        }
        else {
            numChannels.setAttribute("value", Integer.toString(numChannelsValue));
        }

        // BlackIsZero (defaults to TRUE)
        IIOMetadataNode blackIsZero = new IIOMetadataNode("BlackIsZero");
        chroma.appendChild(blackIsZero);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
                blackIsZero.setAttribute("value", "FALSE");
                break;
            default:
                break;
        }

        Entry colorMapTag = ifd.getEntryById(TIFF.TAG_COLOR_MAP);

        if (colorMapTag != null) {
            int[] colorMapValues = (int[]) colorMapTag.getValue();

            IIOMetadataNode palette = new IIOMetadataNode("Palette");
            chroma.appendChild(palette);

            int count = colorMapValues.length / 3;
            for (int i = 0; i < count; i++) {
                IIOMetadataNode paletteEntry = new IIOMetadataNode("PaletteEntry");
                paletteEntry.setAttribute("index", Integer.toString(i));

                // TODO: See TIFFImageReader createIndexColorModel, to detect 8 bit colorMap
                paletteEntry.setAttribute("red", Integer.toString((colorMapValues[i] >> 8) & 0xff));
                paletteEntry.setAttribute("green", Integer.toString((colorMapValues[i + count] >> 8) & 0xff));
                paletteEntry.setAttribute("blue", Integer.toString((colorMapValues[i + count * 2] >> 8) & 0xff));

                palette.appendChild(paletteEntry);
            }
        }

        return chroma;
    } 
                            #location 13 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                @Override
    protected IIOMetadataNode getStandardChromaNode() {
        IIOMetadataNode chroma = new IIOMetadataNode("Chroma");

        // Handle ColorSpaceType (RGB/CMYK/YCbCr etc)...
        Entry photometricTag = ifd.getEntryById(TIFF.TAG_PHOTOMETRIC_INTERPRETATION);
        int photometricValue = getValueAsInt(photometricTag); // No default for this tag!
        int numChannelsValue = getSamplesPerPixelWithFallback();

        IIOMetadataNode colorSpaceType = new IIOMetadataNode("ColorSpaceType");
        chroma.appendChild(colorSpaceType);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO:
            case TIFFBaseline.PHOTOMETRIC_MASK: // It's really a transparency mask/alpha channel, but...
                colorSpaceType.setAttribute("value", "GRAY");
                break;
            case TIFFBaseline.PHOTOMETRIC_RGB:
            case TIFFBaseline.PHOTOMETRIC_PALETTE:
                colorSpaceType.setAttribute("value", "RGB");
                break;
            case TIFFExtension.PHOTOMETRIC_YCBCR:
                colorSpaceType.setAttribute("value", "YCbCr");
                break;
            case TIFFExtension.PHOTOMETRIC_CIELAB:
            case TIFFExtension.PHOTOMETRIC_ICCLAB:
            case TIFFExtension.PHOTOMETRIC_ITULAB:
                colorSpaceType.setAttribute("value", "Lab");
                break;
            case TIFFExtension.PHOTOMETRIC_SEPARATED:
                // TODO: May be CMYK, or something else... Consult InkSet and NumberOfInks!
                if (numChannelsValue == 3) {
                    colorSpaceType.setAttribute("value", "CMY");
                }
                else {
                    colorSpaceType.setAttribute("value", "CMYK");
                }
                break;
            case TIFFCustom.PHOTOMETRIC_LOGL: // ..?
            case TIFFCustom.PHOTOMETRIC_LOGLUV:
                colorSpaceType.setAttribute("value", "Luv");
                break;
            case TIFFCustom.PHOTOMETRIC_CFA:
            case TIFFCustom.PHOTOMETRIC_LINEAR_RAW: // ...or is this RGB?
                colorSpaceType.setAttribute("value", "3CLR");
                break;
            default:
                colorSpaceType.setAttribute("value", Integer.toHexString(numChannelsValue) + "CLR");
                break;
        }

        // NumChannels
        IIOMetadataNode numChannels = new IIOMetadataNode("NumChannels");
        chroma.appendChild(numChannels);
        if (photometricValue == TIFFBaseline.PHOTOMETRIC_PALETTE) {
            numChannels.setAttribute("value", "3");
        }
        else {
            numChannels.setAttribute("value", Integer.toString(numChannelsValue));
        }

        // BlackIsZero (defaults to TRUE)
        IIOMetadataNode blackIsZero = new IIOMetadataNode("BlackIsZero");
        chroma.appendChild(blackIsZero);
        switch (photometricValue) {
            case TIFFBaseline.PHOTOMETRIC_WHITE_IS_ZERO:
                blackIsZero.setAttribute("value", "FALSE");
                break;
            default:
                break;
        }

        Entry colorMapTag = ifd.getEntryById(TIFF.TAG_COLOR_MAP);

        if (colorMapTag != null) {
            int[] colorMapValues = (int[]) colorMapTag.getValue();

            IIOMetadataNode palette = new IIOMetadataNode("Palette");
            chroma.appendChild(palette);

            int count = colorMapValues.length / 3;
            for (int i = 0; i < count; i++) {
                IIOMetadataNode paletteEntry = new IIOMetadataNode("PaletteEntry");
                paletteEntry.setAttribute("index", Integer.toString(i));

                // TODO: See TIFFImageReader createIndexColorModel, to detect 8 bit colorMap
                paletteEntry.setAttribute("red", Integer.toString((colorMapValues[i] >> 8) & 0xff));
                paletteEntry.setAttribute("green", Integer.toString((colorMapValues[i + count] >> 8) & 0xff));
                paletteEntry.setAttribute("blue", Integer.toString((colorMapValues[i + count * 2] >> 8) & 0xff));

                palette.appendChild(paletteEntry);
            }
        }

        return chroma;
    }