Skip to content

Commit

Permalink
fix: use int instead of short to prevent overflowing
Browse files Browse the repository at this point in the history
  • Loading branch information
iyxan23 committed Aug 29, 2024
1 parent 44bdb16 commit c40953c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/iyxan23/zipalignjava/ZipAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ public static void alignZip(RandomAccessFile file, OutputStream out, int alignme

// calculate the amount of alignment needed
long dataPos = fileOffset + 30 + fileNameLen + extraFieldLen + shiftAmount;
short wrongOffset = (short) (dataPos % soFileAlignment);
short alignAmount = wrongOffset == 0 ? 0 : (short) (soFileAlignment - wrongOffset);
int wrongOffset = (int) (dataPos % soFileAlignment);
int alignAmount = wrongOffset == 0 ? 0 : (soFileAlignment - wrongOffset);
shiftAmount += alignAmount;

// only align when alignAmount is not 0 (not already aligned)
Expand Down Expand Up @@ -301,8 +301,8 @@ public static void alignZip(RandomAccessFile file, OutputStream out, int alignme

// calculate the amount of alignment needed
long dataPos = fileOffset + 30 + fileNameLen + extraFieldLen + shiftAmount;
short wrongOffset = (short) (dataPos % alignment);
short alignAmount = wrongOffset == 0 ? 0 : (short) (alignment - wrongOffset);
int wrongOffset = (int) (dataPos % alignment);
int alignAmount = wrongOffset == 0 ? 0 : (alignment - wrongOffset);
shiftAmount += alignAmount;

// only align when alignAmount is not 0 (not already aligned)
Expand Down Expand Up @@ -381,12 +381,12 @@ public static void alignZip(RandomAccessFile file, OutputStream out, int alignme
}

private static class Alignment {
public short alignAmount;
public int alignAmount;
public long extraFieldLenOffset;
public short extraFieldLenValue;
public int extraFieldExtensionOffset;

public Alignment(short alignAmount, long extraFieldLenOffset, short extraFieldLenValue,
public Alignment(int alignAmount, long extraFieldLenOffset, short extraFieldLenValue,
int extraFieldExtensionOffset) {
this.alignAmount = alignAmount;
this.extraFieldLenOffset = extraFieldLenOffset;
Expand Down

0 comments on commit c40953c

Please sign in to comment.