Skip to content

Commit f264c1d

Browse files
authored
Added additional clamping for assertions
1 parent af1e67a commit f264c1d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • server/src/main/java/org/elasticsearch/monitor/os

server/src/main/java/org/elasticsearch/monitor/os/OsStats.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,20 @@ public Swap(long total, long free) {
215215
}
216216

217217
public Swap(StreamInput in) throws IOException {
218-
this.total = in.readLong();
219-
assert this.total >= 0 : "expected total swap to be positive, got: " + total;
220-
this.free = in.readLong();
221-
assert this.free >= 0 : "expected free swap to be positive, got: " + free;
218+
long total = in.readLong();
219+
assert total >= 0 : "expected total swap to be positive, got: " + total;
220+
if (total < 0) {
221+
logger.error("negative total swap [{}] deserialized in swap stats", total);
222+
total = 0;
223+
}
224+
this.total = total;
225+
long free = in.readLong();
226+
assert free >= 0 : "expected free swap to be positive, got: " + free;
227+
if (free < 0) {
228+
logger.error("negative free swap [{}] deserialized in swap stats", free);
229+
free = 0
230+
}
231+
this.free = free;
222232
}
223233

224234
@Override

0 commit comments

Comments
 (0)