Max size for exponent and modulus in RSA and for y, p, q, g in DSS I'm writing a method in Java to read SSH public key in RFC 4253 format, which, in my case, can be either RSA, or DSS. 

What I really need is to read exponent and modulus for RSA key and y, p, q, g values for DSS key, which, according to the standard are of type mpint (multiple precision integers). 

So basically, what I'm doing, is reading an integer first (that becomes "length"), then reading as many bytes as this integer is, then converting this byte array to Java's BigInteger. 

It works perfectly well for valid keys. But the problem appears if there's a malformed key where this first integer is some extremely big number (let's say Integer.MAX_VALUE). Then such an approach results in Requested array size exceeds VM limit exception or some other Java errors related to memory. What I want to do to solve this issue is pre-checking if the length-integer is in a valid range (smaller then some max value).

And here comes the question: what are the max values for exponent, modulus, y, p, q and g? Is there even any maximum for them?
For DSA/DSS the key sizes are restricted by FIPS 186-4, so nothing will ever exceed 4096-bit.

For RSA, anecdotally the largest size anyone supports is 16k-bit, so a Modulus value expressed in 2049 bytes (2048 plus one padding byte).