private static int computeOriginalFileBytesLength(ArrayList<DBRecord> list, Address relocAddr,
			int index, Program program) throws IOException {

		AddressSpace space = relocAddr.getAddressSpace();
		AddressMap addrMap = program.getAddressMap();
		Memory memory = program.getMemory();

		int defaultLength = RelocationManager.getDefaultOriginalByteLength(program);

		int nextIndex = index + 1;
		if (nextIndex < list.size()) {
			DBRecord nextRec = list.get(nextIndex);
			Address nextAddr = addrMap.decodeAddress(nextRec.getLongValue(ADDR_COL));
			if (nextAddr.getAddressSpace().equals(relocAddr.getAddressSpace())) {
				defaultLength = (int) Math.min(defaultLength, nextAddr.subtract(relocAddr));
			}
		}

		if (defaultLength == 0) {
			return 0;
		}

		// Limit relocation length based upon end of address space
		try {
			relocAddr.addNoWrap(defaultLength - 1); // test for valid length
		}
		catch (AddressOverflowException e) {
			defaultLength = (int) space.getMaxAddress().subtract(relocAddr) + 1;
		}

		// Obtain original and current memory bytes at relocation address for comparison
		byte[] originalBytes = RelocationManager.getOriginalBytes(memory, relocAddr, defaultLength);
		byte[] currentBytes = new byte[defaultLength];
		try {
			defaultLength = memory.getBytes(relocAddr, currentBytes);
		}
		catch (MemoryAccessException e) {
			throw new AssertException(e); // unexpected - already checked relocAddr
		}

		// Indentify modification length
		while (defaultLength != 0) {
			int byteIndex = defaultLength - 1;
			if (originalBytes[byteIndex] != currentBytes[byteIndex]) {
				break;
			}
			--defaultLength;
		}
		return defaultLength;
	}
Computes a relocation byte length which will be no greater than the default length
(see {@link RelocationManager#getDefaultOriginalByteLength(Program)} which should not
overlap a subsequent relocation record.
<p>
NOTE: it is possible for a patched instruction to interfere with this logic, however
the result should be no worse than the previously over-extended relocation byte range.

@param list sorted relocation list
@param relocAddr relocation address
@param index relocation index within list
@param program program containing relocations
@return number of original bytes modified or -1 if there is a subsequent relocation at the
same address
@throws IOException if an IO error occurs
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/reloc/RelocationDBAdapter.java