Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix index out of bound issues #2523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/src/main/java/bisq/common/app/Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public static List<Integer> toIntList(Capabilities capabilities) {
* @return a {@link Capabilities} object
*/
public static Capabilities fromIntList(List<Integer> capabilities) {
return new Capabilities(capabilities.stream().map(integer -> Capability.values()[integer]).collect(Collectors.toSet()));
return new Capabilities(capabilities.stream()
.filter(integer -> integer < Capability.values().length)
.map(integer -> Capability.values()[integer])
.collect(Collectors.toSet()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Objects;

import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.concurrent.Immutable;

Expand All @@ -35,6 +36,7 @@
*/
@Immutable
@Value
@Slf4j
public class DaoPhase implements PersistablePayload, ImmutableDaoStateModel {

/**
Expand Down Expand Up @@ -77,7 +79,14 @@ public PB.DaoPhase toProtoMessage() {
}

public static DaoPhase fromProto(PB.DaoPhase proto) {
return new DaoPhase(Phase.values()[proto.getPhaseOrdinal()], proto.getDuration());
int ordinal = proto.getPhaseOrdinal();
if (ordinal >= Phase.values().length) {
log.warn("We tried to access a ordinal outside of the DaoPhase.Phase enum bounds and set it to " +
"UNDEFINED. ordinal={}", ordinal);
return new DaoPhase(Phase.UNDEFINED, 0);
}

return new DaoPhase(Phase.values()[ordinal], proto.getDuration());
}


Expand Down