Skip to content

Commit

Permalink
fix: crash on 1.3.0
Browse files Browse the repository at this point in the history
Closes #543
Closes #439
Closes #514
Closes #540
  • Loading branch information
purofle committed Feb 18, 2024
1 parent 680b362 commit b34c012
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ public void initializeDefaultValues() {

@Override
public void serialize(ByteBufferOutput output) {
output.writeInt(0);
output.writeInt(1);
super.serialize(output);

output.writeString(uuid);
output.writeString(encryption);
if (this instanceof VMessBean) {
Expand Down Expand Up @@ -211,11 +210,33 @@ public void deserialize(ByteBufferInput input) {
realityShortId = input.readString();
}

enableECH = input.readBoolean();
if (enableECH) {
enablePqSignature = input.readBoolean();
disabledDRS = input.readBoolean();
echConfig = input.readString();
if (version >= 1) { // 从老版本升级上来
enableECH = input.readBoolean();
if (enableECH) {
enablePqSignature = input.readBoolean();
disabledDRS = input.readBoolean();
echConfig = input.readString();
}
}

if (version == 0) {
// 从老版本升级上来但是 version == 0, 可能有 enableECH 也可能没有,需要做判断
int position = input.getByteBuffer().position(); // 当前位置

boolean tmpEnableECH = input.readBoolean();
int tmpPacketEncoding = input.readInt();

input.setPosition(position); // 读后归位

if (tmpPacketEncoding != 1 && tmpPacketEncoding != 2) {
input.getByteBuffer().position(position);
enableECH = tmpEnableECH;
if (enableECH) {
enablePqSignature = input.readBoolean();
disabledDRS = input.readBoolean();
echConfig = input.readString();
}
} // 否则后一位就是 packetEncoding
}

packetEncoding = input.readInt();
Expand Down

0 comments on commit b34c012

Please sign in to comment.