package com.google.android.gms.internal.ads; import androidx.work.WorkInfo; import com.applovin.exoplayer2.common.base.Ascii; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import kotlin.jvm.internal.ByteCompanionObject; /* loaded from: classes3.dex */ final class zzgwm extends zzgwp { private final InputStream zze; private final byte[] zzf; private int zzg; private int zzh; private int zzi; private int zzj; private int zzk; private int zzl; public /* synthetic */ zzgwm(InputStream inputStream, int i, zzgwo zzgwoVar) { super(null); this.zzl = Integer.MAX_VALUE; byte[] bArr = zzgye.zzb; this.zze = inputStream; this.zzf = new byte[4096]; this.zzg = 0; this.zzi = 0; this.zzk = 0; } private final List zzI(int i) throws IOException { ArrayList arrayList = new ArrayList(); while (i > 0) { int min = Math.min(i, 4096); byte[] bArr = new byte[min]; int i2 = 0; while (i2 < min) { int read = this.zze.read(bArr, i2, min - i2); if (read == -1) { throw new zzgyg("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."); } this.zzk += read; i2 += read; } i -= min; arrayList.add(bArr); } return arrayList; } private final void zzJ() { int i = this.zzg + this.zzh; this.zzg = i; int i2 = this.zzk + i; int i3 = this.zzl; if (i2 <= i3) { this.zzh = 0; return; } int i4 = i2 - i3; this.zzh = i4; this.zzg = i - i4; } private final void zzK(int i) throws IOException { if (zzL(i)) { return; } if (i <= (Integer.MAX_VALUE - this.zzk) - this.zzi) { throw new zzgyg("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."); } throw new zzgyg("Protocol message was too large. May be malicious. Use CodedInputStream.setSizeLimit() to increase the size limit."); } private final byte[] zzM(int i, boolean z) throws IOException { byte[] zzN = zzN(i); if (zzN != null) { return zzN; } int i2 = this.zzi; int i3 = this.zzg; int i4 = i3 - i2; this.zzk += i3; this.zzi = 0; this.zzg = 0; List zzI = zzI(i - i4); byte[] bArr = new byte[i]; System.arraycopy(this.zzf, i2, bArr, 0, i4); for (byte[] bArr2 : zzI) { int length = bArr2.length; System.arraycopy(bArr2, 0, bArr, i4, length); i4 += length; } return bArr; } private final byte[] zzN(int i) throws IOException { if (i == 0) { return zzgye.zzb; } int i2 = this.zzk; int i3 = this.zzi; int i4 = i2 + i3 + i; if ((-2147483647) + i4 > 0) { throw new zzgyg("Protocol message was too large. May be malicious. Use CodedInputStream.setSizeLimit() to increase the size limit."); } int i5 = this.zzl; if (i4 > i5) { zzC((i5 - i2) - i3); throw new zzgyg("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."); } int i6 = this.zzg - i3; int i7 = i - i6; if (i7 >= 4096) { try { if (i7 > this.zze.available()) { return null; } } catch (zzgyg e) { e.zza(); throw e; } } byte[] bArr = new byte[i]; System.arraycopy(this.zzf, this.zzi, bArr, 0, i6); this.zzk += this.zzg; this.zzi = 0; this.zzg = 0; while (i6 < i) { try { int read = this.zze.read(bArr, i6, i - i6); if (read == -1) { throw new zzgyg("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."); } this.zzk += read; i6 += read; } catch (zzgyg e2) { e2.zza(); throw e2; } } return bArr; } @Override // com.google.android.gms.internal.ads.zzgwp public final boolean zzA() throws IOException { return this.zzi == this.zzg && !zzL(1); } @Override // com.google.android.gms.internal.ads.zzgwp public final boolean zzB() throws IOException { return zzq() != 0; } @Override // com.google.android.gms.internal.ads.zzgwp public final double zza() throws IOException { return Double.longBitsToDouble(zzp()); } @Override // com.google.android.gms.internal.ads.zzgwp public final float zzb() throws IOException { return Float.intBitsToFloat(zzh()); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzc() { return this.zzk + this.zzi; } @Override // com.google.android.gms.internal.ads.zzgwp public final int zze() throws IOException { return zzi(); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzf() throws IOException { return zzh(); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzg() throws IOException { return zzi(); } public final int zzh() throws IOException { int i = this.zzi; if (this.zzg - i < 4) { zzK(4); i = this.zzi; } byte[] bArr = this.zzf; this.zzi = i + 4; int i2 = bArr[i] & 255; int i3 = bArr[i + 1] & 255; int i4 = bArr[i + 2] & 255; return ((bArr[i + 3] & 255) << 24) | (i3 << 8) | i2 | (i4 << 16); } public final int zzi() throws IOException { int i; int i2 = this.zzi; int i3 = this.zzg; if (i3 != i2) { byte[] bArr = this.zzf; int i4 = i2 + 1; byte b = bArr[i2]; if (b >= 0) { this.zzi = i4; return b; } if (i3 - i4 >= 9) { int i5 = i2 + 2; int i6 = (bArr[i4] << 7) ^ b; if (i6 < 0) { i = i6 ^ WorkInfo.STOP_REASON_FOREGROUND_SERVICE_TIMEOUT; } else { int i7 = i2 + 3; int i8 = (bArr[i5] << Ascii.SO) ^ i6; if (i8 >= 0) { i = i8 ^ 16256; } else { int i9 = i2 + 4; int i10 = i8 ^ (bArr[i7] << Ascii.NAK); if (i10 < 0) { i = (-2080896) ^ i10; } else { i7 = i2 + 5; byte b2 = bArr[i9]; int i11 = (i10 ^ (b2 << Ascii.FS)) ^ 266354560; if (b2 < 0) { i9 = i2 + 6; if (bArr[i7] < 0) { i7 = i2 + 7; if (bArr[i9] < 0) { i9 = i2 + 8; if (bArr[i7] < 0) { i7 = i2 + 9; if (bArr[i9] < 0) { int i12 = i2 + 10; if (bArr[i7] >= 0) { i5 = i12; i = i11; } } } } } i = i11; } i = i11; } i5 = i9; } i5 = i7; } this.zzi = i5; return i; } } return (int) zzr(); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzj() throws IOException { return zzh(); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzk() throws IOException { return zzgwp.zzD(zzi()); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzl() throws IOException { if (zzA()) { this.zzj = 0; return 0; } int zzi = zzi(); this.zzj = zzi; if ((zzi >>> 3) != 0) { return zzi; } throw new zzgyg("Protocol message contained an invalid tag (zero)."); } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzm() throws IOException { return zzi(); } @Override // com.google.android.gms.internal.ads.zzgwp public final long zzn() throws IOException { return zzp(); } @Override // com.google.android.gms.internal.ads.zzgwp public final long zzo() throws IOException { return zzq(); } public final long zzp() throws IOException { int i = this.zzi; if (this.zzg - i < 8) { zzK(8); i = this.zzi; } byte[] bArr = this.zzf; this.zzi = i + 8; long j = bArr[i]; long j2 = bArr[i + 2]; long j3 = bArr[i + 3]; return ((bArr[i + 7] & 255) << 56) | (j & 255) | ((bArr[i + 1] & 255) << 8) | ((j2 & 255) << 16) | ((j3 & 255) << 24) | ((bArr[i + 4] & 255) << 32) | ((bArr[i + 5] & 255) << 40) | ((bArr[i + 6] & 255) << 48); } public final long zzq() throws IOException { long j; long j2; int i = this.zzi; int i2 = this.zzg; if (i2 != i) { byte[] bArr = this.zzf; int i3 = i + 1; byte b = bArr[i]; if (b >= 0) { this.zzi = i3; return b; } if (i2 - i3 >= 9) { int i4 = i + 2; int i5 = (bArr[i3] << 7) ^ b; if (i5 < 0) { j = i5 ^ WorkInfo.STOP_REASON_FOREGROUND_SERVICE_TIMEOUT; } else { int i6 = i + 3; int i7 = (bArr[i4] << Ascii.SO) ^ i5; if (i7 >= 0) { j = i7 ^ 16256; } else { int i8 = i + 4; int i9 = i7 ^ (bArr[i6] << Ascii.NAK); if (i9 < 0) { long j3 = (-2080896) ^ i9; i4 = i8; j = j3; } else { i6 = i + 5; long j4 = (bArr[i8] << 28) ^ i9; if (j4 >= 0) { j = j4 ^ 266354560; } else { i4 = i + 6; long j5 = (bArr[i6] << 35) ^ j4; if (j5 < 0) { j2 = -34093383808L; } else { int i10 = i + 7; long j6 = j5 ^ (bArr[i4] << 42); if (j6 >= 0) { j = j6 ^ 4363953127296L; } else { i4 = i + 8; j5 = j6 ^ (bArr[i10] << 49); if (j5 < 0) { j2 = -558586000294016L; } else { i10 = i + 9; long j7 = (j5 ^ (bArr[i4] << 56)) ^ 71499008037633920L; if (j7 < 0) { i4 = i + 10; if (bArr[i10] >= 0) { j = j7; } } else { j = j7; } } } i4 = i10; } j = j5 ^ j2; } } } i4 = i6; } this.zzi = i4; return j; } } return zzr(); } public final long zzr() throws IOException { long j = 0; for (int i = 0; i < 64; i += 7) { if (this.zzi == this.zzg) { zzK(1); } byte[] bArr = this.zzf; int i2 = this.zzi; this.zzi = i2 + 1; j |= (r3 & Byte.MAX_VALUE) << i; if ((bArr[i2] & ByteCompanionObject.MIN_VALUE) == 0) { return j; } } throw new zzgyg("CodedInputStream encountered a malformed varint."); } @Override // com.google.android.gms.internal.ads.zzgwp public final long zzs() throws IOException { return zzp(); } @Override // com.google.android.gms.internal.ads.zzgwp public final long zzt() throws IOException { return zzgwp.zzF(zzq()); } @Override // com.google.android.gms.internal.ads.zzgwp public final long zzu() throws IOException { return zzq(); } @Override // com.google.android.gms.internal.ads.zzgwp public final zzgwj zzv() throws IOException { int zzi = zzi(); int i = this.zzg; int i2 = this.zzi; if (zzi <= i - i2 && zzi > 0) { zzgwj zzv = zzgwj.zzv(this.zzf, i2, zzi); this.zzi += zzi; return zzv; } if (zzi == 0) { return zzgwj.zzb; } if (zzi < 0) { throw new zzgyg("CodedInputStream encountered an embedded string or message which claimed to have negative size."); } byte[] zzN = zzN(zzi); if (zzN != null) { return zzgwj.zzv(zzN, 0, zzN.length); } int i3 = this.zzi; int i4 = this.zzg; int i5 = i4 - i3; this.zzk += i4; this.zzi = 0; this.zzg = 0; List zzI = zzI(zzi - i5); byte[] bArr = new byte[zzi]; System.arraycopy(this.zzf, i3, bArr, 0, i5); for (byte[] bArr2 : zzI) { int length = bArr2.length; System.arraycopy(bArr2, 0, bArr, i5, length); i5 += length; } return new zzgwg(bArr); } @Override // com.google.android.gms.internal.ads.zzgwp public final String zzw() throws IOException { int zzi = zzi(); if (zzi > 0) { int i = this.zzg; int i2 = this.zzi; if (zzi <= i - i2) { String str = new String(this.zzf, i2, zzi, zzgye.zza); this.zzi += zzi; return str; } } if (zzi == 0) { return ""; } if (zzi < 0) { throw new zzgyg("CodedInputStream encountered an embedded string or message which claimed to have negative size."); } if (zzi > this.zzg) { return new String(zzM(zzi, false), zzgye.zza); } zzK(zzi); String str2 = new String(this.zzf, this.zzi, zzi, zzgye.zza); this.zzi += zzi; return str2; } @Override // com.google.android.gms.internal.ads.zzgwp public final String zzx() throws IOException { byte[] zzM; int zzi = zzi(); int i = this.zzi; int i2 = this.zzg; if (zzi <= i2 - i && zzi > 0) { zzM = this.zzf; this.zzi = i + zzi; } else { if (zzi == 0) { return ""; } if (zzi < 0) { throw new zzgyg("CodedInputStream encountered an embedded string or message which claimed to have negative size."); } i = 0; if (zzi <= i2) { zzK(zzi); zzM = this.zzf; this.zzi = zzi; } else { zzM = zzM(zzi, false); } } return zzhat.zzh(zzM, i, zzi); } @Override // com.google.android.gms.internal.ads.zzgwp public final void zzy(int i) throws zzgyg { if (this.zzj != i) { throw new zzgyg("Protocol message end-group tag did not match expected tag."); } } @Override // com.google.android.gms.internal.ads.zzgwp public final void zzz(int i) { this.zzl = i; zzJ(); } private final boolean zzL(int i) throws IOException { int i2 = this.zzi; int i3 = i2 + i; int i4 = this.zzg; if (i3 <= i4) { throw new IllegalStateException("refillBuffer() called when " + i + " bytes were already available in buffer"); } int i5 = this.zzk; if (i > (Integer.MAX_VALUE - i5) - i2 || i5 + i2 + i > this.zzl) { return false; } if (i2 > 0) { if (i4 > i2) { byte[] bArr = this.zzf; System.arraycopy(bArr, i2, bArr, 0, i4 - i2); } i5 = this.zzk + i2; this.zzk = i5; i4 = this.zzg - i2; this.zzg = i4; this.zzi = 0; } try { int read = this.zze.read(this.zzf, i4, Math.min(4096 - i4, (Integer.MAX_VALUE - i5) - i4)); if (read == 0 || read < -1 || read > 4096) { throw new IllegalStateException(String.valueOf(this.zze.getClass()) + "#read(byte[]) returned invalid result: " + read + "\nThe InputStream implementation is buggy."); } if (read <= 0) { return false; } this.zzg += read; zzJ(); if (this.zzg >= i) { return true; } return zzL(i); } catch (zzgyg e) { e.zza(); throw e; } } public final void zzC(int i) throws IOException { int i2 = this.zzg; int i3 = this.zzi; int i4 = i2 - i3; if (i <= i4 && i >= 0) { this.zzi = i3 + i; return; } if (i < 0) { throw new zzgyg("CodedInputStream encountered an embedded string or message which claimed to have negative size."); } int i5 = this.zzk; int i6 = i5 + i3; int i7 = this.zzl; if (i6 + i > i7) { zzC((i7 - i5) - i3); throw new zzgyg("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."); } this.zzk = i6; this.zzg = 0; this.zzi = 0; while (i4 < i) { try { long j = i - i4; try { long skip = this.zze.skip(j); if (skip < 0 || skip > j) { throw new IllegalStateException(String.valueOf(this.zze.getClass()) + "#skip returned invalid result: " + skip + "\nThe InputStream implementation is buggy."); } if (skip == 0) { break; } else { i4 += (int) skip; } } catch (zzgyg e) { e.zza(); throw e; } } catch (Throwable th) { this.zzk += i4; zzJ(); throw th; } } this.zzk += i4; zzJ(); if (i4 >= i) { return; } int i8 = this.zzg; int i9 = i8 - this.zzi; this.zzi = i8; zzK(1); while (true) { int i10 = i - i9; int i11 = this.zzg; if (i10 <= i11) { this.zzi = i10; return; } else { i9 += i11; this.zzi = i11; zzK(1); } } } @Override // com.google.android.gms.internal.ads.zzgwp public final int zzd(int i) throws zzgyg { if (i < 0) { throw new zzgyg("CodedInputStream encountered an embedded string or message which claimed to have negative size."); } int i2 = i + this.zzk + this.zzi; if (i2 < 0) { throw new zzgyg("Failed to parse the message."); } int i3 = this.zzl; if (i2 > i3) { throw new zzgyg("While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length."); } this.zzl = i2; zzJ(); return i3; } }