When i run the script on a boot.img directly. It's appending all blank space to last dtb.
For example i was extracting dtbs from realme X boot.img. Siz eof boot.img was 67.1 MB. The extracted dtbs are shown below.
size of dtbs when extracted from boot.img:

size of dtbs when extracted from zImage (After unpacking with AIK):

Last dtb has a size of 53.5 MB on boot.img case & 173 Bytes on zImage case.
So what's the issue ?
If the kernel size increased a little, while using dtbs extracted from boot.img having remaining blank space appended, will result in a larger image which will eventually fail to flash with a error that partition is full.