Program: 34906
Project: 34906
Buggy source:
protected boolean shiftItemStack(ItemStack stackToShift,int start,int end){
  boolean changed=false;
  if (stackToShift.isStackable()) {
    for (int slotIndex=start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) {
      Slot slot=(Slot)inventorySlots.get(slotIndex);
      ItemStack stackInSlot=slot.getStack();
      if (stackInSlot != null && canStacksMerge(stackInSlot,stackToShift)) {
        int resultingStackSize=stackInSlot.stackSize + stackToShift.stackSize;
        int max=Math.min(stackToShift.getMaxStackSize(),slot.getSlotStackLimit());
        if (resultingStackSize <= max) {
          stackToShift.stackSize=0;
          stackInSlot.stackSize=resultingStackSize;
          slot.onSlotChanged();
          changed=true;
        }
 else         if (stackInSlot.stackSize < max) {
          stackToShift.stackSize-=max - stackInSlot.stackSize;
          stackInSlot.stackSize=max;
          slot.onSlotChanged();
          changed=true;
        }
      }
    }
  }
  if (stackToShift.stackSize > 0) {
    for (int slotIndex=start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) {
      Slot slot=(Slot)inventorySlots.get(slotIndex);
      ItemStack stackInSlot=slot.getStack();
      if (stackInSlot == null) {
        int max=Math.min(stackToShift.getMaxStackSize(),slot.getSlotStackLimit());
        stackInSlot=stackToShift.copy();
        stackInSlot.stackSize=Math.min(stackToShift.stackSize,max);
        stackToShift.stackSize-=stackInSlot.stackSize;
        slot.putStack(stackInSlot);
        slot.onSlotChanged();
        changed=true;
      }
    }
  }
  return changed;
}

Fixed version (ground truth):
private boolean shiftItemStack(ItemStack stackToShift,int start,int end){
  boolean changed=false;
  if (stackToShift.isStackable()) {
    for (int slotIndex=start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) {
      Slot slot=(Slot)inventorySlots.get(slotIndex);
      ItemStack stackInSlot=slot.getStack();
      if (stackInSlot != null && canStacksMerge(stackInSlot,stackToShift)) {
        int resultingStackSize=stackInSlot.stackSize + stackToShift.stackSize;
        int max=Math.min(stackToShift.getMaxStackSize(),slot.getSlotStackLimit());
        if (resultingStackSize <= max) {
          stackToShift.stackSize=0;
          stackInSlot.stackSize=resultingStackSize;
          slot.onSlotChanged();
          changed=true;
        }
 else         if (stackInSlot.stackSize < max) {
          stackToShift.stackSize-=max - stackInSlot.stackSize;
          stackInSlot.stackSize=max;
          slot.onSlotChanged();
          changed=true;
        }
      }
    }
  }
  if (stackToShift.stackSize > 0) {
    for (int slotIndex=start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) {
      Slot slot=(Slot)inventorySlots.get(slotIndex);
      ItemStack stackInSlot=slot.getStack();
      if (stackInSlot == null) {
        int max=Math.min(stackToShift.getMaxStackSize(),slot.getSlotStackLimit());
        stackInSlot=stackToShift.copy();
        stackInSlot.stackSize=Math.min(stackToShift.stackSize,max);
        stackToShift.stackSize-=stackInSlot.stackSize;
        slot.putStack(stackInSlot);
        slot.onSlotChanged();
        changed=true;
      }
    }
  }
  return changed;
}