add some documentation about the new 'no limit' option

This commit is contained in:
David Renshaw 2021-05-09 14:53:54 -04:00
parent 854997703d
commit 07e47d4104
3 changed files with 14 additions and 2 deletions

View file

@ -23,5 +23,5 @@ package org.capnproto;
public interface Arena { public interface Arena {
public SegmentReader tryGetSegment(int id); public SegmentReader tryGetSegment(int id);
public void checkReadLimit(int numBytes); public void checkReadLimit(int numWords);
} }

View file

@ -26,8 +26,8 @@ import java.nio.ByteBuffer;
public final class ReaderArena implements Arena { public final class ReaderArena implements Arena {
// Current limit. -1 means no limit.
public long limit; public long limit;
// current limit
public final ArrayList<SegmentReader> segments; public final ArrayList<SegmentReader> segments;
@ -47,6 +47,7 @@ public final class ReaderArena implements Arena {
@Override @Override
public final void checkReadLimit(int numWords) { public final void checkReadLimit(int numWords) {
if (limit == -1) { if (limit == -1) {
// No limit.
return; return;
} else if (numWords > limit) { } else if (numWords > limit) {
throw new DecodeException("Read limit exceeded."); throw new DecodeException("Read limit exceeded.");

View file

@ -22,7 +22,18 @@
package org.capnproto; package org.capnproto;
public final class ReaderOptions { public final class ReaderOptions {
/**
How many words are allowed to be read before an exception is thrown,
to protect against denial of service attacks.
-1 means "no limit".
*/
public final long traversalLimitInWords; public final long traversalLimitInWords;
/**
How many pointer indirections deep a message may be before an exception
is thrown.
*/
public final int nestingLimit; public final int nestingLimit;
public ReaderOptions(long traversalLimitInWords, int nestingLimit) { public ReaderOptions(long traversalLimitInWords, int nestingLimit) {