Program: 67945
Project: 67945
Buggy source:
protected Dimension getSpecifiedDimension(IImageContent content,int pWidth,boolean scale){
  int imageFileDpiX=0;
  int imageFileDpiY=0;
  Image imageObject=null;
  if (reader.getType() == ImageReader.TYPE_IMAGE_OBJECT || reader.getType() == ImageReader.TYPE_CONVERTED_SVG_OBJECT) {
    try {
      imageObject=Image.getInstance(data);
    }
 catch (    Exception e) {
      logger.log(Level.WARNING,e.getLocalizedMessage());
    }
    if (imageObject != null) {
      imageFileDpiX=imageObject.getDpiX();
      imageFileDpiY=imageObject.getDpiY();
    }
  }
  resolutionX=PropertyUtil.getImageDpi(content,imageFileDpiX,context.getDpi());
  resolutionY=PropertyUtil.getImageDpi(content,imageFileDpiY,context.getDpi());
  try {
    intrinsic=getIntrinsicDimension(content,imageObject);
  }
 catch (  Exception e) {
    logger.log(Level.SEVERE,e.getLocalizedMessage());
  }
  int specifiedWidth=PropertyUtil.getImageDimensionValue(content,content.getWidth(),resolutionX,pWidth);
  int specifiedHeight=PropertyUtil.getImageDimensionValue(content,content.getHeight(),resolutionY,0);
  Dimension dim=new Dimension(DEFAULT_WIDHT,DEFAULT_HEIGHT);
  if (intrinsic == null) {
    dim.setDimension(specifiedWidth == -1 ? DEFAULT_WIDHT : specifiedWidth,specifiedHeight == -1 ? DEFAULT_HEIGHT : specifiedHeight);
    return dim;
  }
  if (scale) {
    double ratio=intrinsic.getRatio();
    if (specifiedWidth >= 0) {
      if (specifiedHeight >= 0) {
        dim.setDimension(specifiedWidth,specifiedHeight);
      }
 else {
        dim.setDimension(specifiedWidth,(int)(specifiedWidth / ratio));
      }
    }
 else {
      if (specifiedHeight >= 0) {
        dim.setDimension((int)(specifiedHeight * ratio),specifiedHeight);
      }
 else {
        dim.setDimension(intrinsic.getWidth(),intrinsic.getHeight());
      }
    }
  }
 else {
    if (specifiedWidth >= 0) {
      if (specifiedHeight >= 0) {
        dim.setDimension(specifiedWidth,specifiedHeight);
      }
 else {
        dim.setDimension(specifiedWidth,intrinsic.getHeight());
      }
    }
 else {
      if (specifiedHeight >= 0) {
        dim.setDimension(intrinsic.getWidth(),specifiedHeight);
      }
 else {
        dim.setDimension(intrinsic.getWidth(),intrinsic.getHeight());
      }
    }
  }
  return dim;
}

Fixed version (ground truth):
protected Dimension getSpecifiedDimension(IImageContent content,int pWidth,boolean scale){
  int imageFileDpiX=0;
  int imageFileDpiY=0;
  Image imageObject=null;
  if (reader.getType() == ImageReader.TYPE_IMAGE_OBJECT || reader.getType() == ImageReader.TYPE_CONVERTED_SVG_OBJECT) {
    try {
      imageObject=Image.getInstance(data);
    }
 catch (    Exception e) {
      logger.log(Level.WARNING,e.getLocalizedMessage());
    }
    if (imageObject != null) {
      imageFileDpiX=imageObject.getDpiX();
      imageFileDpiY=imageObject.getDpiY();
    }
  }
  resolutionX=PropertyUtil.getImageDpi(content,imageFileDpiX,context.getDpi());
  resolutionY=PropertyUtil.getImageDpi(content,imageFileDpiY,context.getDpi());
  try {
    intrinsic=getIntrinsicDimension(content,imageObject);
  }
 catch (  Exception e) {
    logger.log(Level.SEVERE,e.getLocalizedMessage());
  }
  int specifiedWidth=PropertyUtil.getImageDimensionValue(content,content.getWidth(),context.getDpi(),pWidth);
  int specifiedHeight=PropertyUtil.getImageDimensionValue(content,content.getHeight(),context.getDpi(),0);
  Dimension dim=new Dimension(DEFAULT_WIDHT,DEFAULT_HEIGHT);
  if (intrinsic == null) {
    dim.setDimension(specifiedWidth == -1 ? DEFAULT_WIDHT : specifiedWidth,specifiedHeight == -1 ? DEFAULT_HEIGHT : specifiedHeight);
    return dim;
  }
  if (scale) {
    double ratio=intrinsic.getRatio();
    if (specifiedWidth >= 0) {
      if (specifiedHeight >= 0) {
        dim.setDimension(specifiedWidth,specifiedHeight);
      }
 else {
        dim.setDimension(specifiedWidth,(int)(specifiedWidth / ratio));
      }
    }
 else {
      if (specifiedHeight >= 0) {
        dim.setDimension((int)(specifiedHeight * ratio),specifiedHeight);
      }
 else {
        dim.setDimension(intrinsic.getWidth(),intrinsic.getHeight());
      }
    }
  }
 else {
    if (specifiedWidth >= 0) {
      if (specifiedHeight >= 0) {
        dim.setDimension(specifiedWidth,specifiedHeight);
      }
 else {
        dim.setDimension(specifiedWidth,intrinsic.getHeight());
      }
    }
 else {
      if (specifiedHeight >= 0) {
        dim.setDimension(intrinsic.getWidth(),specifiedHeight);
      }
 else {
        dim.setDimension(intrinsic.getWidth(),intrinsic.getHeight());
      }
    }
  }
  return dim;
}