Program: 65739
Project: 65739
Buggy source:
protected void drawBackgroundImage(float x,float y,float width,float height,float imageWidth,float imageHeight,int repeat,String imageUrl,byte[] imageData,float offsetX,float offsetY) throws Exception {
  contentByte.saveState();
  clip(x,y,width,height);
  PdfTemplate image=null;
  if (imageUrl != null) {
    if (pageDevice.getImageCache().containsKey(imageUrl)) {
      image=pageDevice.getImageCache().get(imageUrl);
    }
  }
  if (image == null) {
    Image img=Image.getInstance(imageData);
    if (imageHeight == 0 || imageWidth == 0) {
      int resolutionX=img.getDpiX();
      int resolutionY=img.getDpiY();
      if (0 == resolutionX || 0 == resolutionY) {
        resolutionX=96;
        resolutionY=96;
      }
      imageWidth=img.getPlainWidth() / resolutionX * 72;
      imageHeight=img.getPlainHeight() / resolutionY * 72;
    }
    image=contentByte.createTemplate(imageWidth,imageHeight);
    image.addImage(img,imageWidth,0,0,imageHeight,0,0);
    if (imageUrl != null && image != null) {
      pageDevice.getImageCache().put(imageUrl,image);
    }
  }
  float remainX=width;
  float remainY=height;
  imageWidth=image.getWidth();
  imageHeight=image.getHeight();
  do {
    remainX=width;
    do {
      drawImage(image,x + width - remainX,y + offsetY + height - remainY,imageWidth,imageHeight);
      remainX-=imageWidth;
    }
 while (remainX > 0 && ((repeat & BackgroundImageInfo.REPEAT_X) == BackgroundImageInfo.REPEAT_X));
    remainY-=imageHeight;
  }
 while (remainY > 0 && ((repeat & BackgroundImageInfo.REPEAT_Y) == BackgroundImageInfo.REPEAT_Y));
  contentByte.restoreState();
}

Fixed version (ground truth):
protected void drawBackgroundImage(float x,float y,float width,float height,float imageWidth,float imageHeight,int repeat,String imageUrl,byte[] imageData,float offsetX,float offsetY) throws Exception {
  contentByte.saveState();
  clip(x,y,width,height);
  PdfTemplate image=null;
  if (imageUrl != null) {
    if (pageDevice.getImageCache().containsKey(imageUrl)) {
      image=pageDevice.getImageCache().get(imageUrl);
    }
  }
  if (image == null) {
    Image img=Image.getInstance(imageData);
    if (imageHeight == 0 || imageWidth == 0) {
      int resolutionX=img.getDpiX();
      int resolutionY=img.getDpiY();
      if (0 == resolutionX || 0 == resolutionY) {
        resolutionX=96;
        resolutionY=96;
      }
      imageWidth=img.getPlainWidth() / resolutionX * 72;
      imageHeight=img.getPlainHeight() / resolutionY * 72;
    }
    image=contentByte.createTemplate(imageWidth,imageHeight);
    image.addImage(img,imageWidth,0,0,imageHeight,0,0);
    if (imageUrl != null && image != null) {
      pageDevice.getImageCache().put(imageUrl,image);
    }
  }
  boolean xExtended=(repeat & BackgroundImageInfo.REPEAT_X) == BackgroundImageInfo.REPEAT_X;
  boolean yExtended=(repeat & BackgroundImageInfo.REPEAT_Y) == BackgroundImageInfo.REPEAT_Y;
  imageWidth=image.getWidth();
  imageHeight=image.getHeight();
  float originalX=offsetX;
  float originalY=offsetY;
  if (xExtended) {
    while (originalX > 0)     originalX-=imageWidth;
  }
  if (yExtended) {
    while (originalY > 0)     originalY-=imageHeight;
  }
  float startY=originalY;
  do {
    float startX=originalX;
    do {
      drawImage(image,x + startX,y + startY,imageWidth,imageHeight);
      startX+=imageWidth;
    }
 while (startX < width && xExtended);
    startY+=imageHeight;
  }
 while (startY < height && yExtended);
  contentByte.restoreState();
}