jdk/src/share/native/com/sun/java/util/jar/pack/bands.cpp

Print this page
rev 5678 : 7186957: Improve Pack200 data validation
Reviewed-by: jrose, jjh, mschoene


 170     for (int i = 0; i < length; i++) {
 171       const char* eol = (length > 10 && i % 10 == 0) ? "\n" : " ";
 172       fprintf(u->errstrm, "%s%d", eol, vs[0].getInt());
 173     }
 174     fprintf(u->errstrm, " }\n");
 175   }
 176   (*this) = saved;
 177 }
 178 #endif
 179 
 180 void band::setIndex(cpindex* ix_) {
 181   assert(ix_ == null || ixTag == ix_->ixTag);
 182   ix = ix_;
 183 }
 184 void band::setIndexByTag(byte tag) {
 185   setIndex(u->cp.getIndex(tag));
 186 }
 187 
 188 entry* band::getRefCommon(cpindex* ix_, bool nullOKwithCaller) {
 189   CHECK_0;




 190   assert(ix_->ixTag == ixTag
 191          || (ixTag == CONSTANT_Literal
 192              && ix_->ixTag >= CONSTANT_Integer
 193              && ix_->ixTag <= CONSTANT_String));
 194   int n = vs[0].getInt() - nullOK;
 195   // Note: band-local nullOK means null encodes as 0.
 196   // But nullOKwithCaller means caller is willing to tolerate a null.
 197   entry *ref = ix_->get(n);
 198   if (ref == null && !(nullOKwithCaller && n == -1))
 199     abort(n == -1 ? "null ref" : "bad ref");
 200   return ref;
 201 }
 202 
 203 jlong band::getLong(band& lo_band, bool have_hi) {
 204   band& hi_band = (*this);
 205   assert(lo_band.bn == hi_band.bn + 1);
 206   uint lo = lo_band.getInt();
 207   if (!have_hi) {
 208     assert(hi_band.length == 0);
 209     return makeLong(0, lo);




 170     for (int i = 0; i < length; i++) {
 171       const char* eol = (length > 10 && i % 10 == 0) ? "\n" : " ";
 172       fprintf(u->errstrm, "%s%d", eol, vs[0].getInt());
 173     }
 174     fprintf(u->errstrm, " }\n");
 175   }
 176   (*this) = saved;
 177 }
 178 #endif
 179 
 180 void band::setIndex(cpindex* ix_) {
 181   assert(ix_ == null || ixTag == ix_->ixTag);
 182   ix = ix_;
 183 }
 184 void band::setIndexByTag(byte tag) {
 185   setIndex(u->cp.getIndex(tag));
 186 }
 187 
 188 entry* band::getRefCommon(cpindex* ix_, bool nullOKwithCaller) {
 189   CHECK_0;
 190   if (ix_ == NULL) {
 191       abort("no index");
 192       return NULL;
 193   }
 194   assert(ix_->ixTag == ixTag
 195          || (ixTag == CONSTANT_Literal
 196              && ix_->ixTag >= CONSTANT_Integer
 197              && ix_->ixTag <= CONSTANT_String));
 198   int n = vs[0].getInt() - nullOK;
 199   // Note: band-local nullOK means null encodes as 0.
 200   // But nullOKwithCaller means caller is willing to tolerate a null.
 201   entry *ref = ix_->get(n);
 202   if (ref == null && !(nullOKwithCaller && n == -1))
 203     abort(n == -1 ? "null ref" : "bad ref");
 204   return ref;
 205 }
 206 
 207 jlong band::getLong(band& lo_band, bool have_hi) {
 208   band& hi_band = (*this);
 209   assert(lo_band.bn == hi_band.bn + 1);
 210   uint lo = lo_band.getInt();
 211   if (!have_hi) {
 212     assert(hi_band.length == 0);
 213     return makeLong(0, lo);