package defpackage;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.tukaani.xz.CorruptedInputException;
import org.tukaani.xz.MemoryLimitException;
import org.tukaani.xz.UnsupportedOptionsException;

/* JADX INFO: renamed from: ʽˉᵕ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0101 extends InputStream {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final long f1365;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final DataInputStream f1366;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final long f1367;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public InputStream f1369;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final C2328 f1370;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public final AbstractC3852 f1372;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final boolean f1373;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final long f1374;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public final int f1375;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public long f1368 = 0;

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public boolean f1364 = false;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public final byte[] f1371 = new byte[1];

    public C0101(InputStream inputStream, AbstractC3852 abstractC3852, boolean z, int i, C2470 c2470) throws C0276, IOException {
        char c;
        int i2;
        this.f1374 = -1L;
        this.f1365 = -1L;
        this.f1372 = abstractC3852;
        this.f1373 = z;
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        this.f1366 = dataInputStream;
        int unsignedByte = dataInputStream.readUnsignedByte();
        if (unsignedByte == 0) {
            throw new C0276();
        }
        int i3 = (unsignedByte + 1) * 4;
        this.f1375 = i3;
        byte[] bArr = new byte[i3];
        bArr[0] = (byte) unsignedByte;
        dataInputStream.readFully(bArr, 1, i3 - 1);
        int i4 = i3 - 4;
        if (!ᵽˊᵘᵬ.ᵪᵹᵥᵻ(0, i4, i4, bArr)) {
            throw new CorruptedInputException("XZ Block Header is corrupt");
        }
        int i5 = bArr[1];
        if ((i5 & 60) != 0) {
            throw new UnsupportedOptionsException("Unsupported options in XZ Block Header");
        }
        int i6 = i5 & 3;
        int i7 = i6 + 1;
        long[] jArr = new long[i7];
        byte[][] bArr2 = new byte[i7][];
        int i8 = 0;
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr, 2, i3 - 6);
        try {
            long j = (9223372036854775804L - ((long) i3)) - ((long) abstractC3852.f14716);
            this.f1367 = j;
            if ((bArr[1] & 64) != 0) {
                c = 1;
                long j2 = ᵽˊᵘᵬ.ᵵᵽ(byteArrayInputStream);
                this.f1365 = j2;
                if (j2 == 0 || j2 > j) {
                    throw new CorruptedInputException();
                }
                this.f1367 = j2;
            } else {
                c = 1;
            }
            if ((bArr[c] & 128) != 0) {
                this.f1374 = ᵽˊᵘᵬ.ᵵᵽ(byteArrayInputStream);
            }
            for (int i9 = 0; i9 < i7; i9++) {
                jArr[i9] = ᵽˊᵘᵬ.ᵵᵽ(byteArrayInputStream);
                long j3 = ᵽˊᵘᵬ.ᵵᵽ(byteArrayInputStream);
                if (j3 > byteArrayInputStream.available()) {
                    throw new CorruptedInputException();
                }
                byte[] bArr3 = new byte[(int) j3];
                bArr2[i9] = bArr3;
                byteArrayInputStream.read(bArr3);
            }
            for (int iAvailable = byteArrayInputStream.available(); iAvailable > 0; iAvailable--) {
                if (byteArrayInputStream.read() != 0) {
                    throw new UnsupportedOptionsException("Unsupported options in XZ Block Header");
                }
            }
            InterfaceC5572[] interfaceC5572Arr = new InterfaceC5572[i7];
            int i10 = 0;
            while (i10 < i7) {
                long j4 = jArr[i10];
                if (j4 == 33) {
                    byte[] bArr4 = bArr2[i10];
                    InterfaceC5572 interfaceC5572 = new ᵾːʿ(7);
                    if (bArr4.length == 1) {
                        byte b = bArr4[i8];
                        if ((b & 255) <= 37) {
                            ((ᵾːʿ) interfaceC5572).ᵜᵪʾ = ((b & 1) | 2) << ((b >>> 1) + 11);
                            interfaceC5572Arr[i10] = interfaceC5572;
                        }
                    }
                    throw new UnsupportedOptionsException("Unsupported LZMA2 properties");
                }
                if (j4 == 3) {
                    interfaceC5572Arr[i10] = new ᵾːʿ(bArr2[i10]);
                } else {
                    if (j4 < 4 || j4 > 11) {
                        throw new UnsupportedOptionsException("Unknown Filter ID " + jArr[i10]);
                    }
                    byte[] bArr5 = bArr2[i10];
                    C0655 c0655 = new C0655();
                    c0655.f3093 = j4;
                    if (bArr5.length == 0) {
                        i2 = i8;
                        c0655.f3092 = i2;
                    } else {
                        i2 = i8;
                        if (bArr5.length != 4) {
                            throw new UnsupportedOptionsException("Unsupported BCJ filter properties");
                        }
                        int i11 = i2;
                        int i12 = i11;
                        while (i11 < 4) {
                            i12 |= (bArr5[i11] & 255) << (i11 * 8);
                            i11++;
                        }
                        c0655.f3092 = i12;
                    }
                    interfaceC5572Arr[i10] = c0655;
                    i10++;
                    i8 = i2;
                }
                i2 = i8;
                i10++;
                i8 = i2;
            }
            int i13 = i8;
            for (int i14 = i13; i14 < i6; i14++) {
                if (!interfaceC5572Arr[i14].mo2398()) {
                    throw new UnsupportedOptionsException("Unsupported XZ filter chain");
                }
            }
            if (!interfaceC5572Arr[i6].mo2401()) {
                throw new UnsupportedOptionsException("Unsupported XZ filter chain");
            }
            int i15 = i13;
            int i16 = i15;
            while (i15 < i7) {
                if (interfaceC5572Arr[i15].mo2397()) {
                    i16++;
                }
                i15++;
            }
            if (i16 > 3) {
                throw new UnsupportedOptionsException("Unsupported XZ filter chain");
            }
            if (i >= 0) {
                int iMo2399 = i13;
                while (i13 < i7) {
                    iMo2399 += interfaceC5572Arr[i13].mo2399();
                    i13++;
                }
                if (iMo2399 > i) {
                    throw new MemoryLimitException("" + iMo2399 + " KiB of memory would be needed; limit was " + i + " KiB");
                }
            }
            C2328 c2328 = new C2328(inputStream);
            this.f1370 = c2328;
            this.f1369 = c2328;
            while (i6 >= 0) {
                this.f1369 = interfaceC5572Arr[i6].mo2400(this.f1369, c2470);
                i6--;
            }
        } catch (IOException unused) {
            throw new CorruptedInputException("XZ Block Header is corrupt");
        }
    }

    @Override // java.io.InputStream
    public final int available() {
        return this.f1369.available();
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        try {
            this.f1369.close();
        } catch (IOException unused) {
        }
        this.f1369 = null;
    }

    @Override // java.io.InputStream
    public final int read() {
        byte[] bArr = this.f1371;
        if (read(bArr, 0, 1) == -1) {
            return -1;
        }
        return bArr[0] & 255;
    }

    @Override // java.io.InputStream
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        if (this.f1364) {
            return -1;
        }
        int i3 = this.f1369.read(bArr, i, i2);
        if (i3 > 0) {
            if (this.f1373) {
                this.f1372.mo4104(bArr, i, i3);
            }
            long j = this.f1368 + ((long) i3);
            this.f1368 = j;
            long j2 = this.f1370.f9156;
            if (j2 >= 0 && j2 <= this.f1367 && j >= 0) {
                long j3 = this.f1374;
                if (j3 == -1 || j <= j3) {
                    if (i3 < i2 || j == j3) {
                        if (this.f1369.read() != -1) {
                            throw new CorruptedInputException();
                        }
                        m1174();
                        this.f1364 = true;
                        return i3;
                    }
                }
            }
            throw new CorruptedInputException();
        }
        if (i3 == -1) {
            m1174();
            this.f1364 = true;
        }
        return i3;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m1174() throws IOException {
        long j = this.f1370.f9156;
        long j2 = this.f1365;
        if (j2 == -1 || j2 == j) {
            long j3 = this.f1374;
            if (j3 == -1 || j3 == this.f1368) {
                while (true) {
                    long j4 = 1 + j;
                    long j5 = j & 3;
                    DataInputStream dataInputStream = this.f1366;
                    if (j5 == 0) {
                        AbstractC3852 abstractC3852 = this.f1372;
                        byte[] bArr = new byte[abstractC3852.f14716];
                        dataInputStream.readFully(bArr);
                        if (this.f1373 && !Arrays.equals(abstractC3852.mo4103(), bArr)) {
                            throw new CorruptedInputException(AbstractC3653.m8231(new StringBuilder("Integrity check ("), abstractC3852.f14715, ") does not match"));
                        }
                        return;
                    }
                    if (dataInputStream.readUnsignedByte() != 0) {
                        throw new CorruptedInputException();
                    }
                    j = j4;
                }
            }
        }
        throw new CorruptedInputException();
    }
}
