fix: add splitscreen, fix dlcs not loading, major RCE vuln fix on packet net, fix chunk loading on non-server clients, persistent saves

note: I changed how XUID works, player data might be wiped on old saves, save items on a chest or similar before trying to load old saves on new version
This commit is contained in:
NOTPIES 2026-03-07 18:30:53 -03:00
parent e077f9250f
commit d017bfc30a
76 changed files with 14967 additions and 4486 deletions

View file

@ -31,12 +31,12 @@ endif()
target_compile_definitions(MinecraftWorld PRIVATE target_compile_definitions(MinecraftWorld PRIVATE
$<$<CONFIG:Debug>:_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_DEBUG;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64> $<$<CONFIG:Debug>:_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_DEBUG;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64>
$<$<NOT:$<CONFIG:Debug>>:_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64> $<$<NOT:$<CONFIG:Debug>>:_LARGE_WORLDS;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64>
) )
target_compile_definitions(MinecraftClient PRIVATE target_compile_definitions(MinecraftClient PRIVATE
$<$<CONFIG:Debug>:_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_DEBUG;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64> $<$<CONFIG:Debug>:_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_DEBUG;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64>
$<$<NOT:$<CONFIG:Debug>>:_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64> $<$<NOT:$<CONFIG:Debug>>:_LARGE_WORLDS;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64>
) )
target_include_directories(MinecraftWorld PUBLIC target_include_directories(MinecraftWorld PUBLIC

View file

@ -400,6 +400,7 @@ void Chunk::rebuild()
} }
Tile *tile = Tile::tiles[tileId]; Tile *tile = Tile::tiles[tileId];
if (!tile) continue;
if (currentLayer == 0 && tile->isEntityTile()) if (currentLayer == 0 && tile->isEntityTile())
{ {
shared_ptr<TileEntity> et = region->getTileEntity(x, y, z); shared_ptr<TileEntity> et = region->getTileEntity(x, y, z);
@ -746,9 +747,9 @@ void Chunk::rebuild_SPU()
{ {
// 4J - get tile from those copied into our local array in earlier optimisation // 4J - get tile from those copied into our local array in earlier optimisation
unsigned char tileId = pOutData->getTile(x,y,z); unsigned char tileId = pOutData->getTile(x,y,z);
if (tileId > 0) if (tileId > 0 && tileId != 0xff)
{ {
if (currentLayer == 0 && Tile::tiles[tileId]->isEntityTile()) if (currentLayer == 0 && Tile::tiles[tileId] && Tile::tiles[tileId]->isEntityTile())
{ {
shared_ptr<TileEntity> et = region.getTileEntity(x, y, z); shared_ptr<TileEntity> et = region.getTileEntity(x, y, z);
if (TileEntityRenderDispatcher::instance->hasRenderer(et)) if (TileEntityRenderDispatcher::instance->hasRenderer(et))
@ -761,6 +762,7 @@ void Chunk::rebuild_SPU()
{ {
Tile *tile = Tile::tiles[tileId]; Tile *tile = Tile::tiles[tileId];
if (!tile) continue;
int renderLayer = tile->getRenderLayer(); int renderLayer = tile->getRenderLayer();
if (renderLayer != currentLayer) if (renderLayer != currentLayer)

View file

@ -753,6 +753,7 @@ void ClientConnection::handleAddPlayer(shared_ptr<AddPlayerPacket> packet)
player->yRotp = packet->yRot; player->yRotp = packet->yRot;
player->yHeadRot = packet->yHeadRot * 360 / 256.0f; player->yHeadRot = packet->yHeadRot * 360 / 256.0f;
player->setXuid(packet->xuid); player->setXuid(packet->xuid);
player->setOnlineXuid(packet->OnlineXuid);
#ifdef _DURANGO #ifdef _DURANGO
// On Durango request player display name from network manager // On Durango request player display name from network manager
@ -765,11 +766,11 @@ void ClientConnection::handleAddPlayer(shared_ptr<AddPlayerPacket> packet)
#ifdef _WINDOWS64 #ifdef _WINDOWS64
{ {
PlayerUID pktXuid = player->getXuid(); PlayerUID netXuid = packet->OnlineXuid;
const PlayerUID WIN64_XUID_BASE = (PlayerUID)0xe000d45248242f2e; const PlayerUID WIN64_XUID_BASE = (PlayerUID)0xe000d45248242f2e;
if (pktXuid >= WIN64_XUID_BASE && pktXuid < WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS) if (netXuid >= WIN64_XUID_BASE && netXuid < WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS)
{ {
BYTE smallId = (BYTE)(pktXuid - WIN64_XUID_BASE); BYTE smallId = (BYTE)(netXuid - WIN64_XUID_BASE);
INetworkPlayer *np = g_NetworkManager.GetPlayerBySmallId(smallId); INetworkPlayer *np = g_NetworkManager.GetPlayerBySmallId(smallId);
if (np != NULL) if (np != NULL)
{ {
@ -923,39 +924,6 @@ void ClientConnection::handleMoveEntitySmall(shared_ptr<MoveEntityPacketSmall> p
void ClientConnection::handleRemoveEntity(shared_ptr<RemoveEntitiesPacket> packet) void ClientConnection::handleRemoveEntity(shared_ptr<RemoveEntitiesPacket> packet)
{ {
#ifdef _WINDOWS64
if (!g_NetworkManager.IsHost())
{
for (int i = 0; i < packet->ids.length; i++)
{
shared_ptr<Entity> entity = getEntity(packet->ids[i]);
if (entity != NULL && entity->GetType() == eTYPE_PLAYER)
{
shared_ptr<Player> player = dynamic_pointer_cast<Player>(entity);
if (player != NULL)
{
PlayerUID xuid = player->getXuid();
INetworkPlayer *np = g_NetworkManager.GetPlayerByXuid(xuid);
if (np != NULL)
{
NetworkPlayerXbox *npx = (NetworkPlayerXbox *)np;
IQNetPlayer *qp = npx->GetQNetPlayer();
if (qp != NULL)
{
extern CPlatformNetworkManagerStub *g_pPlatformNetworkManager;
g_pPlatformNetworkManager->NotifyPlayerLeaving(qp);
qp->m_smallId = 0;
qp->m_isRemote = false;
qp->m_isHostPlayer = false;
qp->m_gamertag[0] = 0;
qp->SetCustomDataValue(0);
}
}
}
}
}
}
#endif
for (int i = 0; i < packet->ids.length; i++) for (int i = 0; i < packet->ids.length; i++)
{ {
level->removeEntity(packet->ids[i]); level->removeEntity(packet->ids[i]);
@ -1036,7 +1004,7 @@ void ClientConnection::handleChunkVisibility(shared_ptr<ChunkVisibilityPacket> p
void ClientConnection::handleChunkTilesUpdate(shared_ptr<ChunkTilesUpdatePacket> packet) void ClientConnection::handleChunkTilesUpdate(shared_ptr<ChunkTilesUpdatePacket> packet)
{ {
// 4J - changed to encode level in packet if (packet->levelIdx >= minecraft->levels.length) return;
MultiPlayerLevel *dimensionLevel = (MultiPlayerLevel *)minecraft->levels[packet->levelIdx]; MultiPlayerLevel *dimensionLevel = (MultiPlayerLevel *)minecraft->levels[packet->levelIdx];
if( dimensionLevel ) if( dimensionLevel )
{ {
@ -1105,7 +1073,7 @@ void ClientConnection::handleChunkTilesUpdate(shared_ptr<ChunkTilesUpdatePacket>
void ClientConnection::handleBlockRegionUpdate(shared_ptr<BlockRegionUpdatePacket> packet) void ClientConnection::handleBlockRegionUpdate(shared_ptr<BlockRegionUpdatePacket> packet)
{ {
// 4J - changed to encode level in packet if (packet->levelIdx >= minecraft->levels.length) return;
MultiPlayerLevel *dimensionLevel = (MultiPlayerLevel *)minecraft->levels[packet->levelIdx]; MultiPlayerLevel *dimensionLevel = (MultiPlayerLevel *)minecraft->levels[packet->levelIdx];
if( dimensionLevel ) if( dimensionLevel )
{ {
@ -1149,7 +1117,7 @@ void ClientConnection::handleTileUpdate(shared_ptr<TileUpdatePacket> packet)
packet->block = 0; packet->block = 0;
destroyTilePacket = true; destroyTilePacket = true;
} }
// 4J - changed to encode level in packet if (packet->levelIdx >= minecraft->levels.length) return;
MultiPlayerLevel *dimensionLevel = (MultiPlayerLevel *)minecraft->levels[packet->levelIdx]; MultiPlayerLevel *dimensionLevel = (MultiPlayerLevel *)minecraft->levels[packet->levelIdx];
if( dimensionLevel ) if( dimensionLevel )
{ {
@ -2162,6 +2130,7 @@ void ClientConnection::handleAddMob(shared_ptr<AddMobPacket> packet)
float xRot = packet->xRot * 360 / 256.0f; float xRot = packet->xRot * 360 / 256.0f;
shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>(EntityIO::newById(packet->type, level)); shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>(EntityIO::newById(packet->type, level));
if (mob == nullptr) return;
mob->xp = packet->x; mob->xp = packet->x;
mob->yp = packet->y; mob->yp = packet->y;
mob->zp = packet->z; mob->zp = packet->z;
@ -3235,10 +3204,11 @@ void ClientConnection::handleCustomPayload(shared_ptr<CustomPayloadPacket> custo
} }
#else #else
UIScene *scene = ui.GetTopScene(m_userIndex, eUILayer_Scene); UIScene *scene = ui.GetTopScene(m_userIndex, eUILayer_Scene);
UIScene_TradingMenu *screen = (UIScene_TradingMenu *)scene; UIScene_TradingMenu *screen = dynamic_cast<UIScene_TradingMenu *>(scene);
trader = screen->getMerchant(); if (screen != nullptr)
trader = screen->getMerchant();
#endif #endif
if (trader == nullptr) return;
MerchantRecipeList *recipeList = MerchantRecipeList::createFromStream(&input); MerchantRecipeList *recipeList = MerchantRecipeList::createFromStream(&input);
trader->overrideOffers(recipeList); trader->overrideOffers(recipeList);
} }

View file

@ -231,6 +231,8 @@ void CPlatformNetworkManagerStub::DoWork()
BYTE disconnectedSmallId; BYTE disconnectedSmallId;
while (WinsockNetLayer::PopDisconnectedSmallId(&disconnectedSmallId)) while (WinsockNetLayer::PopDisconnectedSmallId(&disconnectedSmallId))
{ {
if (disconnectedSmallId == 0) continue;
if (WinsockNetLayer::IsSmallIdConnected(disconnectedSmallId)) continue;
IQNetPlayer *qnetPlayer = m_pIQNet->GetPlayerBySmallId(disconnectedSmallId); IQNetPlayer *qnetPlayer = m_pIQNet->GetPlayerBySmallId(disconnectedSmallId);
if (qnetPlayer != NULL && qnetPlayer->m_smallId == disconnectedSmallId) if (qnetPlayer != NULL && qnetPlayer->m_smallId == disconnectedSmallId)
{ {
@ -246,6 +248,16 @@ void CPlatformNetworkManagerStub::DoWork()
} }
} }
BYTE joinedSmallId;
while (WinsockNetLayer::PopPendingJoinSmallId(&joinedSmallId))
{
IQNetPlayer *qnetPlayer = m_pIQNet->GetPlayerBySmallId(joinedSmallId);
if (qnetPlayer != NULL && qnetPlayer->m_smallId == joinedSmallId)
{
NotifyPlayerJoined(qnetPlayer);
}
}
for (int i = 1; i < MINECRAFT_NET_MAX_PLAYERS; i++) for (int i = 1; i < MINECRAFT_NET_MAX_PLAYERS; i++)
{ {
IQNetPlayer *qp = &IQNet::m_player[i]; IQNetPlayer *qp = &IQNet::m_player[i];
@ -293,12 +305,29 @@ int CPlatformNetworkManagerStub::GetLocalPlayerMask(int playerIndex)
bool CPlatformNetworkManagerStub::AddLocalPlayerByUserIndex( int userIndex ) bool CPlatformNetworkManagerStub::AddLocalPlayerByUserIndex( int userIndex )
{ {
if (m_pIQNet->AddLocalPlayerByUserIndex(userIndex) != S_OK) return false;
NotifyPlayerJoined(m_pIQNet->GetLocalPlayerByUserIndex(userIndex)); NotifyPlayerJoined(m_pIQNet->GetLocalPlayerByUserIndex(userIndex));
return ( m_pIQNet->AddLocalPlayerByUserIndex(userIndex) == S_OK ); return true;
} }
bool CPlatformNetworkManagerStub::RemoveLocalPlayerByUserIndex( int userIndex ) bool CPlatformNetworkManagerStub::RemoveLocalPlayerByUserIndex( int userIndex )
{ {
#ifdef _WINDOWS64
if (userIndex > 0 && userIndex < XUSER_MAX_COUNT)
{
IQNetPlayer *qnetPlayer = m_pIQNet->GetLocalPlayerByUserIndex(userIndex);
if (qnetPlayer != NULL)
{
NotifyPlayerLeaving(qnetPlayer);
qnetPlayer->m_isRemote = true;
qnetPlayer->m_isHostPlayer = false;
qnetPlayer->m_gamertag[0] = 0;
qnetPlayer->SetCustomDataValue(0);
if (IQNet::s_playerCount > 1)
IQNet::s_playerCount--;
}
}
#endif
return true; return true;
} }
@ -378,6 +407,8 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame,
IQNet::m_player[0].m_isRemote = false; IQNet::m_player[0].m_isRemote = false;
IQNet::m_player[0].m_isHostPlayer = true; IQNet::m_player[0].m_isHostPlayer = true;
IQNet::s_playerCount = 1; IQNet::s_playerCount = 1;
extern wchar_t g_Win64UsernameW[17];
wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW);
#endif #endif
_HostGame( localUsersMask, publicSlots, privateSlots ); _HostGame( localUsersMask, publicSlots, privateSlots );

View file

@ -993,12 +993,19 @@ void UIScene_CreateWorldMenu::checkStateAndStartGame()
#endif #endif
else else
{ {
//ProfileManager.RequestSignInUI(false, false, false, true, false,&CScene_MultiGameCreate::StartGame_SignInReturned, this,ProfileManager.GetPrimaryPad()); #ifdef _WINDOWS64
SignInInfo info;
info.Func = &UIScene_CreateWorldMenu::StartGame_SignInReturned;
info.lpParam = this;
info.requireOnline = m_MoreOptionsParams.bOnlineGame;
UIScene_CreateWorldMenu::StartGame_SignInReturned(this, true, ProfileManager.GetPrimaryPad());
#else
SignInInfo info; SignInInfo info;
info.Func = &UIScene_CreateWorldMenu::StartGame_SignInReturned; info.Func = &UIScene_CreateWorldMenu::StartGame_SignInReturned;
info.lpParam = this; info.lpParam = this;
info.requireOnline = m_MoreOptionsParams.bOnlineGame; info.requireOnline = m_MoreOptionsParams.bOnlineGame;
ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_QuadrantSignin,&info); ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_QuadrantSignin,&info);
#endif
} }
} }
else else
@ -1355,12 +1362,16 @@ int UIScene_CreateWorldMenu::ConfirmCreateReturned(void *pParam,int iPad,C4JStor
if(isClientSide && app.IsLocalMultiplayerAvailable()) if(isClientSide && app.IsLocalMultiplayerAvailable())
{ {
#ifdef _WINDOWS64
UIScene_CreateWorldMenu::StartGame_SignInReturned(pClass, true, ProfileManager.GetPrimaryPad());
#else
//ProfileManager.RequestSignInUI(false, false, false, true, false,&UIScene_CreateWorldMenu::StartGame_SignInReturned, pClass,ProfileManager.GetPrimaryPad()); //ProfileManager.RequestSignInUI(false, false, false, true, false,&UIScene_CreateWorldMenu::StartGame_SignInReturned, pClass,ProfileManager.GetPrimaryPad());
SignInInfo info; SignInInfo info;
info.Func = &UIScene_CreateWorldMenu::StartGame_SignInReturned; info.Func = &UIScene_CreateWorldMenu::StartGame_SignInReturned;
info.lpParam = pClass; info.lpParam = pClass;
info.requireOnline = pClass->m_MoreOptionsParams.bOnlineGame; info.requireOnline = pClass->m_MoreOptionsParams.bOnlineGame;
ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_QuadrantSignin,&info); ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_QuadrantSignin,&info);
#endif
} }
else else
{ {

View file

@ -1341,7 +1341,12 @@ int UIScene_LoadMenu::LoadDataComplete(void *pParam)
#endif #endif
else else
{ {
#ifdef _WINDOWS64
DWORD dwLocalUsersMask = CGameNetworkManager::GetLocalPlayerMask(ProfileManager.GetPrimaryPad());
StartGameFromSave(pClass, dwLocalUsersMask);
#else
pClass->m_bRequestQuadrantSignin = true; pClass->m_bRequestQuadrantSignin = true;
#endif
} }
} }
} }

View file

@ -351,6 +351,10 @@ void UIScene_MainMenu::handlePress(F64 controlId, F64 childId)
ui.NavigateToScene(primaryPad,eUIScene_TrialExitUpsell); ui.NavigateToScene(primaryPad,eUIScene_TrialExitUpsell);
} }
break; break;
#elif defined _WINDOWS64
case eControl_Exit:
app.ExitGame();
break;
#endif #endif
#ifdef _DURANGO #ifdef _DURANGO

View file

@ -1,16 +1,13 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream /* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2011 Mark Adler * Copyright (C) 1995-2011, 2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#include "zutil.h" #include "zutil.h"
#define local static #define BASE 65521U /* largest prime smaller than 65536 */
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552 #define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@ -61,11 +58,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
#endif #endif
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len) uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long sum2; unsigned long sum2;
unsigned n; unsigned n;
@ -132,11 +125,12 @@ uLong ZEXPORT adler32(adler, buf, len)
} }
/* ========================================================================= */ /* ========================================================================= */
local uLong adler32_combine_(adler1, adler2, len2) uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) {
uLong adler1; return adler32_z(adler, buf, len);
uLong adler2; }
z_off64_t len2;
{ /* ========================================================================= */
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) {
unsigned long sum1; unsigned long sum1;
unsigned long sum2; unsigned long sum2;
unsigned rem; unsigned rem;
@ -155,24 +149,16 @@ local uLong adler32_combine_(adler1, adler2, len2)
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE;
if (sum1 >= BASE) sum1 -= BASE; if (sum1 >= BASE) sum1 -= BASE;
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
if (sum2 >= BASE) sum2 -= BASE; if (sum2 >= BASE) sum2 -= BASE;
return sum1 | (sum2 << 16); return sum1 | (sum2 << 16);
} }
/* ========================================================================= */ /* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2) uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) {
uLong adler1;
uLong adler2;
z_off_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }
uLong ZEXPORT adler32_combine64(adler1, adler2, len2) uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) {
uLong adler1;
uLong adler2;
z_off64_t len2;
{
return adler32_combine_(adler1, adler2, len2); return adler32_combine_(adler1, adler2, len2);
} }

View file

@ -1,5 +1,5 @@
/* compress.c -- compress a memory buffer /* compress.c -- compress a memory buffer
* Copyright (C) 1995-2005 Jean-loup Gailly. * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -19,25 +19,15 @@
memory, Z_BUF_ERROR if there was not enough room in the output buffer, memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid. Z_STREAM_ERROR if the level parameter is invalid.
*/ */
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong sourceLen, int level) {
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1;
uLong left;
stream.next_in = (z_const Bytef *)source; left = *destLen;
stream.avail_in = (uInt)sourceLen; *destLen = 0;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.zfree = (free_func)0;
@ -46,36 +36,40 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
err = deflateInit(&stream, level); err = deflateInit(&stream, level);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH); stream.next_out = dest;
if (err != Z_STREAM_END) { stream.avail_out = 0;
deflateEnd(&stream); stream.next_in = (z_const Bytef *)source;
return err == Z_OK ? Z_BUF_ERROR : err; stream.avail_in = 0;
}
*destLen = stream.total_out;
err = deflateEnd(&stream); do {
return err; if (stream.avail_out == 0) {
stream.avail_out = left > (uLong)max ? max : (uInt)left;
left -= stream.avail_out;
}
if (stream.avail_in == 0) {
stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
sourceLen -= stream.avail_in;
}
err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
} while (err == Z_OK);
*destLen = stream.total_out;
deflateEnd(&stream);
return err == Z_STREAM_END ? Z_OK : err;
} }
/* =========================================================================== /* ===========================================================================
*/ */
int ZEXPORT compress (dest, destLen, source, sourceLen) int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong sourceLen) {
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
} }
/* =========================================================================== /* ===========================================================================
If the default memLevel or windowBits for deflateInit() is changed, then If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated. this function needs to be updated.
*/ */
uLong ZEXPORT compressBound (sourceLen) uLong ZEXPORT compressBound(uLong sourceLen) {
uLong sourceLen;
{
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
(sourceLen >> 25) + 13; (sourceLen >> 25) + 13;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/* deflate.h -- internal compression state /* deflate.h -- internal compression state
* Copyright (C) 1995-2012 Jean-loup Gailly * Copyright (C) 1995-2024 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -23,6 +23,10 @@
# define GZIP # define GZIP
#endif #endif
/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
the cost of a larger memory footprint */
/* #define LIT_MEM */
/* =========================================================================== /* ===========================================================================
* Internal compression state. * Internal compression state.
*/ */
@ -51,13 +55,16 @@
#define Buf_size 16 #define Buf_size 16
/* size of bit buffer in bi_buf */ /* size of bit buffer in bi_buf */
#define INIT_STATE 42 #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
#define EXTRA_STATE 69 #ifdef GZIP
#define NAME_STATE 73 # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
#define COMMENT_STATE 91 #endif
#define HCRC_STATE 103 #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
#define BUSY_STATE 113 #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
#define FINISH_STATE 666 #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
#define FINISH_STATE 666 /* stream complete */
/* Stream status */ /* Stream status */
@ -83,7 +90,7 @@ typedef struct static_tree_desc_s static_tree_desc;
typedef struct tree_desc_s { typedef struct tree_desc_s {
ct_data *dyn_tree; /* the dynamic tree */ ct_data *dyn_tree; /* the dynamic tree */
int max_code; /* largest code with non zero frequency */ int max_code; /* largest code with non zero frequency */
static_tree_desc *stat_desc; /* the corresponding static tree */ const static_tree_desc *stat_desc; /* the corresponding static tree */
} FAR tree_desc; } FAR tree_desc;
typedef ush Pos; typedef ush Pos;
@ -100,10 +107,10 @@ typedef struct internal_state {
Bytef *pending_buf; /* output still pending */ Bytef *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */ ulg pending_buf_size; /* size of pending_buf */
Bytef *pending_out; /* next pending byte to output to the stream */ Bytef *pending_out; /* next pending byte to output to the stream */
uInt pending; /* nb of bytes in the pending buffer */ ulg pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
gz_headerp gzhead; /* gzip header information to write */ gz_headerp gzhead; /* gzip header information to write */
uInt gzindex; /* where in extra, name, or comment */ ulg gzindex; /* where in extra, name, or comment */
Byte method; /* can only be DEFLATED */ Byte method; /* can only be DEFLATED */
int last_flush; /* value of flush param for previous deflate call */ int last_flush; /* value of flush param for previous deflate call */
@ -214,7 +221,14 @@ typedef struct internal_state {
/* Depth of each subtree used as tie breaker for trees of equal frequency /* Depth of each subtree used as tie breaker for trees of equal frequency
*/ */
uchf *l_buf; /* buffer for literals or lengths */ #ifdef LIT_MEM
# define LIT_BUFS 5
ushf *d_buf; /* buffer for distances */
uchf *l_buf; /* buffer for literals/lengths */
#else
# define LIT_BUFS 4
uchf *sym_buf; /* buffer for distances and literals/lengths */
#endif
uInt lit_bufsize; uInt lit_bufsize;
/* Size of match buffer for literals/lengths. There are 4 reasons for /* Size of match buffer for literals/lengths. There are 4 reasons for
@ -236,20 +250,15 @@ typedef struct internal_state {
* - I can't count above 4 * - I can't count above 4
*/ */
uInt last_lit; /* running index in l_buf */ uInt sym_next; /* running index in symbol buffer */
uInt sym_end; /* symbol table full when sym_next reaches this */
ushf *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
*/
ulg opt_len; /* bit length of current block with optimal trees */ ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */ ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */ uInt matches; /* number of string matches in current block */
uInt insert; /* bytes at end of window left to insert */ uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG #ifdef ZLIB_DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif #endif
@ -275,7 +284,7 @@ typedef struct internal_state {
/* Output a byte on the stream. /* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf. * IN assertion: there is enough room in pending_buf.
*/ */
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
@ -293,14 +302,14 @@ typedef struct internal_state {
memory checker errors from longest match routines */ memory checker errors from longest match routines */
/* in trees.c */ /* in trees.c */
void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); void ZLIB_INTERNAL _tr_init(deflate_state *s);
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
ulg stored_len, int last)); ulg stored_len, int last);
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); void ZLIB_INTERNAL _tr_align(deflate_state *s);
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
ulg stored_len, int last)); ulg stored_len, int last);
#define d_code(dist) \ #define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
@ -309,7 +318,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
* used. * used.
*/ */
#ifndef DEBUG #ifndef ZLIB_DEBUG
/* Inline versions of _tr_tally for speed: */ /* Inline versions of _tr_tally for speed: */
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
@ -320,24 +329,46 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
extern const uch ZLIB_INTERNAL _dist_code[]; extern const uch ZLIB_INTERNAL _dist_code[];
#endif #endif
#ifdef LIT_MEM
# define _tr_tally_lit(s, c, flush) \ # define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \ { uch cc = (c); \
s->d_buf[s->last_lit] = 0; \ s->d_buf[s->sym_next] = 0; \
s->l_buf[s->last_lit++] = cc; \ s->l_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \ s->dyn_ltree[cc].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \ flush = (s->sym_next == s->sym_end); \
} }
# define _tr_tally_dist(s, distance, length, flush) \ # define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (length); \ { uch len = (uch)(length); \
ush dist = (distance); \ ush dist = (ush)(distance); \
s->d_buf[s->last_lit] = dist; \ s->d_buf[s->sym_next] = dist; \
s->l_buf[s->last_lit++] = len; \ s->l_buf[s->sym_next++] = len; \
dist--; \ dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \ s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \ flush = (s->sym_next == s->sym_end); \
} }
#else #else
# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = cc; \
s->dyn_ltree[cc].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (uch)(length); \
ush dist = (ush)(distance); \
s->sym_buf[s->sym_next++] = (uch)dist; \
s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
s->sym_buf[s->sym_next++] = len; \
dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
#endif
#else
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
# define _tr_tally_dist(s, distance, length, flush) \ # define _tr_tally_dist(s, distance, length, flush) \
flush = _tr_tally(s, distance, length) flush = _tr_tally(s, distance, length)

View file

@ -8,9 +8,7 @@
/* gzclose() is in a separate file so that it is linked in only if it is used. /* gzclose() is in a separate file so that it is linked in only if it is used.
That way the other gzclose functions can be used instead to avoid linking in That way the other gzclose functions can be used instead to avoid linking in
unneeded compression or decompression routines. */ unneeded compression or decompression routines. */
int ZEXPORT gzclose(file) int ZEXPORT gzclose(gzFile file) {
gzFile file;
{
#ifndef NO_GZCOMPRESS #ifndef NO_GZCOMPRESS
gz_statep state; gz_statep state;

View file

@ -1,5 +1,5 @@
/* gzguts.h -- zlib internal header definitions for gz* operations /* gzguts.h -- zlib internal header definitions for gz* operations
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler * Copyright (C) 2004-2024 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -7,9 +7,8 @@
# ifndef _LARGEFILE_SOURCE # ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1 # define _LARGEFILE_SOURCE 1
# endif # endif
# ifdef _FILE_OFFSET_BITS # undef _FILE_OFFSET_BITS
# undef _FILE_OFFSET_BITS # undef _TIME_BITS
# endif
#endif #endif
#ifdef HAVE_HIDDEN #ifdef HAVE_HIDDEN
@ -25,6 +24,10 @@
# include <stdlib.h> # include <stdlib.h>
# include <limits.h> # include <limits.h>
#endif #endif
#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include <fcntl.h> #include <fcntl.h>
#ifdef _WIN32 #ifdef _WIN32
@ -35,6 +38,10 @@
# include <io.h> # include <io.h>
#endif #endif
#if defined(_WIN32)
# define WIDECHAR
#endif
#ifdef WINAPI_FAMILY #ifdef WINAPI_FAMILY
# define open _open # define open _open
# define read _read # define read _read
@ -95,23 +102,24 @@
# endif # endif
#endif #endif
/* unlike snprintf (which is required in C99, yet still not supported by /* unlike snprintf (which is required in C99), _snprintf does not guarantee
Microsoft more than a decade later!), _snprintf does not guarantee null null termination of the result -- however this is only used in gzlib.c where
termination of the result -- however this is only used in gzlib.c where
the result is assured to fit in the space provided */ the result is assured to fit in the space provided */
#ifdef _MSC_VER #if defined(_MSC_VER) && _MSC_VER < 1900
# define snprintf _snprintf # define snprintf _snprintf
#endif #endif
#ifndef local #ifndef local
# define local static # define local static
#endif #endif
/* compile with -Dlocal if your debugger can't find static symbols */ /* since "static" is used to mean two completely different things in C, we
define "local" for the non-static meaning of "static", for readability
(compile with -Dlocal if your debugger can't find static symbols) */
/* gz* functions always use library allocation functions */ /* gz* functions always use library allocation functions */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
/* get errno and strerror definition */ /* get errno and strerror definition */
@ -129,10 +137,10 @@
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int);
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gztell64(gzFile);
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile);
#endif #endif
/* default memLevel */ /* default memLevel */
@ -170,7 +178,7 @@ typedef struct {
char *path; /* path or fd for error messages */ char *path; /* path or fd for error messages */
unsigned size; /* buffer size, zero if not allocated yet */ unsigned size; /* buffer size, zero if not allocated yet */
unsigned want; /* requested buffer size, default is GZBUFSIZE */ unsigned want; /* requested buffer size, default is GZBUFSIZE */
unsigned char *in; /* input buffer */ unsigned char *in; /* input buffer (double-sized when writing) */
unsigned char *out; /* output buffer (double-sized when reading) */ unsigned char *out; /* output buffer (double-sized when reading) */
int direct; /* 0 if processing gzip, 1 if transparent */ int direct; /* 0 if processing gzip, 1 if transparent */
/* just for reading */ /* just for reading */
@ -181,6 +189,7 @@ typedef struct {
/* just for writing */ /* just for writing */
int level; /* compression level */ int level; /* compression level */
int strategy; /* compression strategy */ int strategy; /* compression strategy */
int reset; /* true if a reset is pending after a Z_FINISH */
/* seek request */ /* seek request */
z_off64_t skip; /* amount to skip (already rewound if backwards) */ z_off64_t skip; /* amount to skip (already rewound if backwards) */
int seek; /* true if seek request pending */ int seek; /* true if seek request pending */
@ -193,17 +202,13 @@ typedef struct {
typedef gz_state FAR *gz_statep; typedef gz_state FAR *gz_statep;
/* shared functions */ /* shared functions */
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
#if defined UNDER_CE #if defined UNDER_CE
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
#endif #endif
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
value -- needed when comparing unsigned to z_off64_t, which is signed value -- needed when comparing unsigned to z_off64_t, which is signed
(possible z_off64_t types off_t, off64_t, and long are all signed) */ (possible z_off64_t types off_t, off64_t, and long are all signed) */
#ifdef INT_MAX unsigned ZLIB_INTERNAL gz_intmax(void);
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) #define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#else
unsigned ZLIB_INTERNAL gz_intmax OF((void));
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
#endif

View file

@ -1,5 +1,5 @@
/* gzlib.c -- zlib functions common to reading and writing gzip files /* gzlib.c -- zlib functions common to reading and writing gzip files
* Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler * Copyright (C) 2004-2024 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -15,10 +15,6 @@
#endif #endif
#endif #endif
/* Local functions */
local void gz_reset OF((gz_statep));
local gzFile gz_open OF((const void *, int, const char *));
#if defined UNDER_CE #if defined UNDER_CE
/* Map the Windows error number in ERROR to a locale-dependent error message /* Map the Windows error number in ERROR to a locale-dependent error message
@ -30,9 +26,7 @@ local gzFile gz_open OF((const void *, int, const char *));
The gz_strwinerror function does not change the current setting of The gz_strwinerror function does not change the current setting of
GetLastError. */ GetLastError. */
char ZLIB_INTERNAL *gz_strwinerror (error) char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
DWORD error;
{
static char buf[1024]; static char buf[1024];
wchar_t *msgbuf; wchar_t *msgbuf;
@ -72,15 +66,15 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
#endif /* UNDER_CE */ #endif /* UNDER_CE */
/* Reset gzip file state */ /* Reset gzip file state */
local void gz_reset(state) local void gz_reset(gz_statep state) {
gz_statep state;
{
state->x.have = 0; /* no output data available */ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */ if (state->mode == GZ_READ) { /* for reading ... */
state->eof = 0; /* not at end of file */ state->eof = 0; /* not at end of file */
state->past = 0; /* have not read past end yet */ state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */ state->how = LOOK; /* look for gzip header */
} }
else /* for writing ... */
state->reset = 0; /* no deflateReset pending */
state->seek = 0; /* no seek request pending */ state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */ gz_error(state, Z_OK, NULL); /* clear error */
state->x.pos = 0; /* no uncompressed data yet */ state->x.pos = 0; /* no uncompressed data yet */
@ -88,13 +82,9 @@ local void gz_reset(state)
} }
/* Open a gzip file either by name or file descriptor. */ /* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(path, fd, mode) local gzFile gz_open(const void *path, int fd, const char *mode) {
const void *path;
int fd;
const char *mode;
{
gz_statep state; gz_statep state;
size_t len; z_size_t len;
int oflag; int oflag;
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
int cloexec = 0; int cloexec = 0;
@ -188,10 +178,10 @@ local gzFile gz_open(path, fd, mode)
} }
/* save the path name for error messages */ /* save the path name for error messages */
#ifdef _WIN32 #ifdef WIDECHAR
if (fd == -2) { if (fd == -2) {
len = wcstombs(NULL, path, 0); len = wcstombs(NULL, path, 0);
if (len == (size_t)-1) if (len == (z_size_t)-1)
len = 0; len = 0;
} }
else else
@ -202,7 +192,7 @@ local gzFile gz_open(path, fd, mode)
free(state); free(state);
return NULL; return NULL;
} }
#ifdef _WIN32 #ifdef WIDECHAR
if (fd == -2) if (fd == -2)
if (len) if (len)
wcstombs(state->path, path, len + 1); wcstombs(state->path, path, len + 1);
@ -211,7 +201,7 @@ local gzFile gz_open(path, fd, mode)
else else
#endif #endif
#if !defined(NO_snprintf) && !defined(NO_vsnprintf) #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
snprintf(state->path, len + 1, "%s", (const char *)path); (void)snprintf(state->path, len + 1, "%s", (const char *)path);
#else #else
strcpy(state->path, path); strcpy(state->path, path);
#endif #endif
@ -239,7 +229,7 @@ local gzFile gz_open(path, fd, mode)
/* open the file with the appropriate flags (or just use fd) */ /* open the file with the appropriate flags (or just use fd) */
state->fd = fd > -1 ? fd : ( state->fd = fd > -1 ? fd : (
#ifdef _WIN32 #ifdef WIDECHAR
fd == -2 ? _wopen(path, oflag, 0666) : fd == -2 ? _wopen(path, oflag, 0666) :
#endif #endif
open((const char *)path, oflag, 0666)); open((const char *)path, oflag, 0666));
@ -248,8 +238,10 @@ local gzFile gz_open(path, fd, mode)
free(state); free(state);
return NULL; return NULL;
} }
if (state->mode == GZ_APPEND) if (state->mode == GZ_APPEND) {
LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
state->mode = GZ_WRITE; /* simplify later checks */ state->mode = GZ_WRITE; /* simplify later checks */
}
/* save the current position for rewinding (only if reading) */ /* save the current position for rewinding (only if reading) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ) {
@ -265,33 +257,24 @@ local gzFile gz_open(path, fd, mode)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen(path, mode) gzFile ZEXPORT gzopen(const char *path, const char *mode) {
const char *path;
const char *mode;
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzopen64(path, mode) gzFile ZEXPORT gzopen64(const char *path, const char *mode) {
const char *path;
const char *mode;
{
return gz_open(path, -1, mode); return gz_open(path, -1, mode);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
gzFile ZEXPORT gzdopen(fd, mode) gzFile ZEXPORT gzdopen(int fd, const char *mode) {
int fd;
const char *mode;
{
char *path; /* identifier for error messages */ char *path; /* identifier for error messages */
gzFile gz; gzFile gz;
if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
return NULL; return NULL;
#if !defined(NO_snprintf) && !defined(NO_vsnprintf) #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */ (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
#else #else
sprintf(path, "<fd:%d>", fd); /* for debugging */ sprintf(path, "<fd:%d>", fd); /* for debugging */
#endif #endif
@ -301,20 +284,14 @@ gzFile ZEXPORT gzdopen(fd, mode)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
#ifdef _WIN32 #ifdef WIDECHAR
gzFile ZEXPORT gzopen_w(path, mode) gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) {
const wchar_t *path;
const char *mode;
{
return gz_open(path, -2, mode); return gz_open(path, -2, mode);
} }
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzbuffer(file, size) int ZEXPORT gzbuffer(gzFile file, unsigned size) {
gzFile file;
unsigned size;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -329,16 +306,16 @@ int ZEXPORT gzbuffer(file, size)
return -1; return -1;
/* check and set requested size */ /* check and set requested size */
if (size < 2) if ((size << 1) < size)
size = 2; /* need two bytes to check magic header */ return -1; /* need to be able to double it */
if (size < 8)
size = 8; /* needed to behave well with flushing */
state->want = size; state->want = size;
return 0; return 0;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzrewind(file) int ZEXPORT gzrewind(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@ -359,11 +336,7 @@ int ZEXPORT gzrewind(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzseek64(file, offset, whence) z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
gzFile file;
z_off64_t offset;
int whence;
{
unsigned n; unsigned n;
z_off64_t ret; z_off64_t ret;
gz_statep state; gz_statep state;
@ -393,7 +366,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
/* if within raw area while reading, just go there */ /* if within raw area while reading, just go there */
if (state->mode == GZ_READ && state->how == COPY && if (state->mode == GZ_READ && state->how == COPY &&
state->x.pos + offset >= 0) { state->x.pos + offset >= 0) {
ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
if (ret == -1) if (ret == -1)
return -1; return -1;
state->x.have = 0; state->x.have = 0;
@ -436,11 +409,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzseek(file, offset, whence) z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) {
gzFile file;
z_off_t offset;
int whence;
{
z_off64_t ret; z_off64_t ret;
ret = gzseek64(file, (z_off64_t)offset, whence); ret = gzseek64(file, (z_off64_t)offset, whence);
@ -448,9 +417,7 @@ z_off_t ZEXPORT gzseek(file, offset, whence)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gztell64(file) z_off64_t ZEXPORT gztell64(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -465,9 +432,7 @@ z_off64_t ZEXPORT gztell64(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gztell(file) z_off_t ZEXPORT gztell(gzFile file) {
gzFile file;
{
z_off64_t ret; z_off64_t ret;
ret = gztell64(file); ret = gztell64(file);
@ -475,9 +440,7 @@ z_off_t ZEXPORT gztell(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off64_t ZEXPORT gzoffset64(file) z_off64_t ZEXPORT gzoffset64(gzFile file) {
gzFile file;
{
z_off64_t offset; z_off64_t offset;
gz_statep state; gz_statep state;
@ -498,9 +461,7 @@ z_off64_t ZEXPORT gzoffset64(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
z_off_t ZEXPORT gzoffset(file) z_off_t ZEXPORT gzoffset(gzFile file) {
gzFile file;
{
z_off64_t ret; z_off64_t ret;
ret = gzoffset64(file); ret = gzoffset64(file);
@ -508,9 +469,7 @@ z_off_t ZEXPORT gzoffset(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzeof(file) int ZEXPORT gzeof(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -525,10 +484,7 @@ int ZEXPORT gzeof(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
const char * ZEXPORT gzerror(file, errnum) const char * ZEXPORT gzerror(gzFile file, int *errnum) {
gzFile file;
int *errnum;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -546,9 +502,7 @@ const char * ZEXPORT gzerror(file, errnum)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
void ZEXPORT gzclearerr(file) void ZEXPORT gzclearerr(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure and check integrity */ /* get internal structure and check integrity */
@ -572,11 +526,7 @@ void ZEXPORT gzclearerr(file)
memory). Simply save the error message as a static string. If there is an memory). Simply save the error message as a static string. If there is an
allocation failure constructing the error message, then convert the error to allocation failure constructing the error message, then convert the error to
out of memory. */ out of memory. */
void ZLIB_INTERNAL gz_error(state, err, msg) void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
gz_statep state;
int err;
const char *msg;
{
/* free previously allocated message and clear */ /* free previously allocated message and clear */
if (state->msg != NULL) { if (state->msg != NULL) {
if (state->err != Z_MEM_ERROR) if (state->err != Z_MEM_ERROR)
@ -604,31 +554,29 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
return; return;
} }
#if !defined(NO_snprintf) && !defined(NO_vsnprintf) #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
"%s%s%s", state->path, ": ", msg); "%s%s%s", state->path, ": ", msg);
#else #else
strcpy(state->msg, state->path); strcpy(state->msg, state->path);
strcat(state->msg, ": "); strcat(state->msg, ": ");
strcat(state->msg, msg); strcat(state->msg, msg);
#endif #endif
return;
} }
#ifndef INT_MAX
/* portably return maximum value for an int (when limits.h presumed not /* portably return maximum value for an int (when limits.h presumed not
available) -- we need to do this to cover cases where 2's complement not available) -- we need to do this to cover cases where 2's complement not
used, since C standard permits 1's complement and sign-bit representations, used, since C standard permits 1's complement and sign-bit representations,
otherwise we could just use ((unsigned)-1) >> 1 */ otherwise we could just use ((unsigned)-1) >> 1 */
unsigned ZLIB_INTERNAL gz_intmax() unsigned ZLIB_INTERNAL gz_intmax(void) {
{ #ifdef INT_MAX
unsigned p, q; return INT_MAX;
#else
p = 1; unsigned p = 1, q;
do { do {
q = p; q = p;
p <<= 1; p <<= 1;
p++; p++;
} while (p > q); } while (p > q);
return q >> 1; return q >> 1;
}
#endif #endif
}

View file

@ -1,36 +1,28 @@
/* gzread.c -- zlib functions for reading gzip files /* gzread.c -- zlib functions for reading gzip files
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler * Copyright (C) 2004-2017 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "gzguts.h" #include "gzguts.h"
/* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
local int gz_avail OF((gz_statep));
local int gz_look OF((gz_statep));
local int gz_decomp OF((gz_statep));
local int gz_fetch OF((gz_statep));
local int gz_skip OF((gz_statep, z_off64_t));
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
state->fd, and update state->eof, state->err, and state->msg as appropriate. state->fd, and update state->eof, state->err, and state->msg as appropriate.
This function needs to loop on read(), since read() is not guaranteed to This function needs to loop on read(), since read() is not guaranteed to
read the number of bytes requested, depending on the type of descriptor. */ read the number of bytes requested, depending on the type of descriptor. */
local int gz_load(state, buf, len, have) local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
gz_statep state; unsigned *have) {
unsigned char *buf;
unsigned len;
unsigned *have;
{
int ret; int ret;
unsigned get, max = ((unsigned)-1 >> 2) + 1;
*have = 0; *have = 0;
do { do {
ret = read(state->fd, buf + *have, len - *have); get = len - *have;
if (get > max)
get = max;
ret = read(state->fd, buf + *have, get);
if (ret <= 0) if (ret <= 0)
break; break;
*have += ret; *have += (unsigned)ret;
} while (*have < len); } while (*have < len);
if (ret < 0) { if (ret < 0) {
gz_error(state, Z_ERRNO, zstrerror()); gz_error(state, Z_ERRNO, zstrerror());
@ -48,9 +40,7 @@ local int gz_load(state, buf, len, have)
If strm->avail_in != 0, then the current data is moved to the beginning of If strm->avail_in != 0, then the current data is moved to the beginning of
the input buffer, and then the remainder of the buffer is loaded with the the input buffer, and then the remainder of the buffer is loaded with the
available data from the input file. */ available data from the input file. */
local int gz_avail(state) local int gz_avail(gz_statep state) {
gz_statep state;
{
unsigned got; unsigned got;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@ -83,9 +73,7 @@ local int gz_avail(state)
case, all further file reads will be directly to either the output buffer or case, all further file reads will be directly to either the output buffer or
a user buffer. If decompressing, the inflate state will be initialized. a user buffer. If decompressing, the inflate state will be initialized.
gz_look() will return 0 on success or -1 on failure. */ gz_look() will return 0 on success or -1 on failure. */
local int gz_look(state) local int gz_look(gz_statep state) {
gz_statep state;
{
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate read buffers and inflate memory */ /* allocate read buffers and inflate memory */
@ -94,10 +82,8 @@ local int gz_look(state)
state->in = (unsigned char *)malloc(state->want); state->in = (unsigned char *)malloc(state->want);
state->out = (unsigned char *)malloc(state->want << 1); state->out = (unsigned char *)malloc(state->want << 1);
if (state->in == NULL || state->out == NULL) { if (state->in == NULL || state->out == NULL) {
if (state->out != NULL) free(state->out);
free(state->out); free(state->in);
if (state->in != NULL)
free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
} }
@ -154,11 +140,9 @@ local int gz_look(state)
the output buffer is larger than the input buffer, which also assures the output buffer is larger than the input buffer, which also assures
space for gzungetc() */ space for gzungetc() */
state->x.next = state->out; state->x.next = state->out;
if (strm->avail_in) { memcpy(state->x.next, strm->next_in, strm->avail_in);
memcpy(state->x.next, strm->next_in, strm->avail_in); state->x.have = strm->avail_in;
state->x.have = strm->avail_in; strm->avail_in = 0;
strm->avail_in = 0;
}
state->how = COPY; state->how = COPY;
state->direct = 1; state->direct = 1;
return 0; return 0;
@ -169,9 +153,7 @@ local int gz_look(state)
data. If the gzip stream completes, state->how is reset to LOOK to look for data. If the gzip stream completes, state->how is reset to LOOK to look for
the next gzip stream or raw data, once state->x.have is depleted. Returns 0 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
on success, -1 on failure. */ on success, -1 on failure. */
local int gz_decomp(state) local int gz_decomp(gz_statep state) {
gz_statep state;
{
int ret = Z_OK; int ret = Z_OK;
unsigned had; unsigned had;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@ -223,9 +205,7 @@ local int gz_decomp(state)
looked for to determine whether to copy or decompress. Returns -1 on error, looked for to determine whether to copy or decompress. Returns -1 on error,
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
end of the input file has been reached and all data has been processed. */ end of the input file has been reached and all data has been processed. */
local int gz_fetch(state) local int gz_fetch(gz_statep state) {
gz_statep state;
{
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
do { do {
@ -253,10 +233,7 @@ local int gz_fetch(state)
} }
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
local int gz_skip(state, len) local int gz_skip(gz_statep state, z_off64_t len) {
gz_statep state;
z_off64_t len;
{
unsigned n; unsigned n;
/* skip over len bytes or reach end-of-file, whichever comes first */ /* skip over len bytes or reach end-of-file, whichever comes first */
@ -284,33 +261,13 @@ local int gz_skip(state, len)
return 0; return 0;
} }
/* -- see zlib.h -- */ /* Read len bytes into buf from file, or less than len up to the end of the
int ZEXPORT gzread(file, buf, len) input. Return the number of bytes read. If zero is returned, either the
gzFile file; end of file was reached, or there was an error. state->err must be
voidp buf; consulted in that case to determine which. */
unsigned len; local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
{ z_size_t got;
unsigned got, n; unsigned n;
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
strm = &(state->strm);
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return -1;
}
/* if len is zero, avoid unnecessary operations */ /* if len is zero, avoid unnecessary operations */
if (len == 0) if (len == 0)
@ -320,32 +277,38 @@ int ZEXPORT gzread(file, buf, len)
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_skip(state, state->skip) == -1) if (gz_skip(state, state->skip) == -1)
return -1; return 0;
} }
/* get len bytes to buf, or less than len if at the end */ /* get len bytes to buf, or less than len if at the end */
got = 0; got = 0;
do { do {
/* set n to the maximum amount of len that fits in an unsigned int */
n = (unsigned)-1;
if (n > len)
n = (unsigned)len;
/* first just try copying data from the output buffer */ /* first just try copying data from the output buffer */
if (state->x.have) { if (state->x.have) {
n = state->x.have > len ? len : state->x.have; if (state->x.have < n)
n = state->x.have;
memcpy(buf, state->x.next, n); memcpy(buf, state->x.next, n);
state->x.next += n; state->x.next += n;
state->x.have -= n; state->x.have -= n;
} }
/* output buffer empty -- return if we're at the end of the input */ /* output buffer empty -- return if we're at the end of the input */
else if (state->eof && strm->avail_in == 0) { else if (state->eof && state->strm.avail_in == 0) {
state->past = 1; /* tried to read past end */ state->past = 1; /* tried to read past end */
break; break;
} }
/* need output data -- for small len or new stream load up our output /* need output data -- for small len or new stream load up our output
buffer */ buffer */
else if (state->how == LOOK || len < (state->size << 1)) { else if (state->how == LOOK || n < (state->size << 1)) {
/* get more output, looking for header if required */ /* get more output, looking for header if required */
if (gz_fetch(state) == -1) if (gz_fetch(state) == -1)
return -1; return 0;
continue; /* no progress yet -- go back to copy above */ continue; /* no progress yet -- go back to copy above */
/* the copy above assures that we will leave with space in the /* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */ output buffer, allowing at least one gzungetc() to succeed */
@ -353,16 +316,16 @@ int ZEXPORT gzread(file, buf, len)
/* large len -- read directly into user buffer */ /* large len -- read directly into user buffer */
else if (state->how == COPY) { /* read directly */ else if (state->how == COPY) { /* read directly */
if (gz_load(state, (unsigned char *)buf, len, &n) == -1) if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
return -1; return 0;
} }
/* large len -- decompress directly into user buffer */ /* large len -- decompress directly into user buffer */
else { /* state->how == GZIP */ else { /* state->how == GZIP */
strm->avail_out = len; state->strm.avail_out = n;
strm->next_out = (unsigned char *)buf; state->strm.next_out = (unsigned char *)buf;
if (gz_decomp(state) == -1) if (gz_decomp(state) == -1)
return -1; return 0;
n = state->x.have; n = state->x.have;
state->x.have = 0; state->x.have = 0;
} }
@ -374,8 +337,66 @@ int ZEXPORT gzread(file, buf, len)
state->x.pos += n; state->x.pos += n;
} while (len); } while (len);
/* return number of bytes read into user buffer (will fit in int) */ /* return number of bytes read into user buffer */
return (int)got; return got;
}
/* -- see zlib.h -- */
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
gz_statep state;
/* get internal structure */
if (file == NULL)
return -1;
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids a flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
return -1;
}
/* read len or fewer bytes to buf */
len = (unsigned)gz_read(state, buf, len);
/* check for an error */
if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
/* return the number of bytes read (this is assured to fit in an int) */
return (int)len;
}
/* -- see zlib.h -- */
z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) {
z_size_t len;
gz_statep state;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR))
return 0;
/* compute bytes to read -- error on overflow */
len = nitems * size;
if (size && len / size != nitems) {
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
return 0;
}
/* read len or fewer bytes to buf, return the number of full items read */
return len ? gz_read(state, buf, len) / size : 0;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
@ -384,10 +405,7 @@ int ZEXPORT gzread(file, buf, len)
#else #else
# undef gzgetc # undef gzgetc
#endif #endif
int ZEXPORT gzgetc(file) int ZEXPORT gzgetc(gzFile file) {
gzFile file;
{
int ret;
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
@ -408,22 +426,16 @@ int ZEXPORT gzgetc(file)
return *(state->x.next)++; return *(state->x.next)++;
} }
/* nothing there -- try gzread() */ /* nothing there -- try gz_read() */
ret = gzread(file, buf, 1); return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
return ret < 1 ? -1 : buf[0];
} }
int ZEXPORT gzgetc_(file) int ZEXPORT gzgetc_(gzFile file) {
gzFile file;
{
return gzgetc(file); return gzgetc(file);
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzungetc(c, file) int ZEXPORT gzungetc(int c, gzFile file) {
int c;
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@ -431,6 +443,10 @@ int ZEXPORT gzungetc(c, file)
return -1; return -1;
state = (gz_statep)file; state = (gz_statep)file;
/* in case this was just opened, set up the input buffer */
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
(void)gz_look(state);
/* check that we're reading and that there's no (serious) error */ /* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ || if (state->mode != GZ_READ ||
(state->err != Z_OK && state->err != Z_BUF_ERROR)) (state->err != Z_OK && state->err != Z_BUF_ERROR))
@ -451,7 +467,7 @@ int ZEXPORT gzungetc(c, file)
if (state->x.have == 0) { if (state->x.have == 0) {
state->x.have = 1; state->x.have = 1;
state->x.next = state->out + (state->size << 1) - 1; state->x.next = state->out + (state->size << 1) - 1;
state->x.next[0] = c; state->x.next[0] = (unsigned char)c;
state->x.pos--; state->x.pos--;
state->past = 0; state->past = 0;
return c; return c;
@ -473,18 +489,14 @@ int ZEXPORT gzungetc(c, file)
} }
state->x.have++; state->x.have++;
state->x.next--; state->x.next--;
state->x.next[0] = c; state->x.next[0] = (unsigned char)c;
state->x.pos--; state->x.pos--;
state->past = 0; state->past = 0;
return c; return c;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
char * ZEXPORT gzgets(file, buf, len) char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
gzFile file;
char *buf;
int len;
{
unsigned left, n; unsigned left, n;
char *str; char *str;
unsigned char *eol; unsigned char *eol;
@ -544,9 +556,7 @@ char * ZEXPORT gzgets(file, buf, len)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzdirect(file) int ZEXPORT gzdirect(gzFile file) {
gzFile file;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
@ -564,9 +574,7 @@ int ZEXPORT gzdirect(file)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_r(file) int ZEXPORT gzclose_r(gzFile file) {
gzFile file;
{
int ret, err; int ret, err;
gz_statep state; gz_statep state;

View file

@ -1,25 +1,19 @@
/* gzwrite.c -- zlib functions for writing gzip files /* gzwrite.c -- zlib functions for writing gzip files
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler * Copyright (C) 2004-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "gzguts.h" #include "gzguts.h"
/* Local functions */
local int gz_init OF((gz_statep));
local int gz_comp OF((gz_statep, int));
local int gz_zero OF((gz_statep, z_off64_t));
/* Initialize state for writing a gzip file. Mark initialization by setting /* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on failure or 0 on success. */ state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
local int gz_init(state) success. */
gz_statep state; local int gz_init(gz_statep state) {
{
int ret; int ret;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate input buffer */ /* allocate input buffer (double size for gzprintf) */
state->in = (unsigned char *)malloc(state->want); state->in = (unsigned char *)malloc(state->want << 1);
if (state->in == NULL) { if (state->in == NULL) {
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
@ -47,6 +41,7 @@ local int gz_init(state)
gz_error(state, Z_MEM_ERROR, "out of memory"); gz_error(state, Z_MEM_ERROR, "out of memory");
return -1; return -1;
} }
strm->next_in = NULL;
} }
/* mark state as initialized */ /* mark state as initialized */
@ -62,17 +57,14 @@ local int gz_init(state)
} }
/* Compress whatever is at avail_in and next_in and write to the output file. /* Compress whatever is at avail_in and next_in and write to the output file.
Return -1 if there is an error writing to the output file, otherwise 0. Return -1 if there is an error writing to the output file or if gz_init()
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, fails to allocate memory, otherwise 0. flush is assumed to be a valid
then the deflate() state is reset to start a new gzip stream. If gz->direct deflate() flush value. If flush is Z_FINISH, then the deflate() state is
is true, then simply write to the output file without compressing, and reset to start a new gzip stream. If gz->direct is true, then simply write
ignore flush. */ to the output file without compressing, and ignore flush. */
local int gz_comp(state, flush) local int gz_comp(gz_statep state, int flush) {
gz_statep state; int ret, writ;
int flush; unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
{
int ret, got;
unsigned have;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
/* allocate memory if this is the first time through */ /* allocate memory if this is the first time through */
@ -81,15 +73,28 @@ local int gz_comp(state, flush)
/* write directly if requested */ /* write directly if requested */
if (state->direct) { if (state->direct) {
got = write(state->fd, strm->next_in, strm->avail_in); while (strm->avail_in) {
if (got < 0 || (unsigned)got != strm->avail_in) { put = strm->avail_in > max ? max : strm->avail_in;
gz_error(state, Z_ERRNO, zstrerror()); writ = write(state->fd, strm->next_in, put);
return -1; if (writ < 0) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
strm->avail_in -= (unsigned)writ;
strm->next_in += writ;
} }
strm->avail_in = 0;
return 0; return 0;
} }
/* check for a pending reset */
if (state->reset) {
/* don't start a new gzip member unless there is data to write */
if (strm->avail_in == 0)
return 0;
deflateReset(strm);
state->reset = 0;
}
/* run deflate() on provided input until it produces no more output */ /* run deflate() on provided input until it produces no more output */
ret = Z_OK; ret = Z_OK;
do { do {
@ -97,17 +102,21 @@ local int gz_comp(state, flush)
doing Z_FINISH then don't write until we get to Z_STREAM_END */ doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) { (flush != Z_FINISH || ret == Z_STREAM_END))) {
have = (unsigned)(strm->next_out - state->x.next); while (strm->next_out > state->x.next) {
if (have && ((got = write(state->fd, state->x.next, have)) < 0 || put = strm->next_out - state->x.next > (int)max ? max :
(unsigned)got != have)) { (unsigned)(strm->next_out - state->x.next);
gz_error(state, Z_ERRNO, zstrerror()); writ = write(state->fd, state->x.next, put);
return -1; if (writ < 0) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
state->x.next += writ;
} }
if (strm->avail_out == 0) { if (strm->avail_out == 0) {
strm->avail_out = state->size; strm->avail_out = state->size;
strm->next_out = state->out; strm->next_out = state->out;
state->x.next = state->out;
} }
state->x.next = strm->next_out;
} }
/* compress */ /* compress */
@ -123,17 +132,15 @@ local int gz_comp(state, flush)
/* if that completed a deflate stream, allow another to start */ /* if that completed a deflate stream, allow another to start */
if (flush == Z_FINISH) if (flush == Z_FINISH)
deflateReset(strm); state->reset = 1;
/* all done, no errors */ /* all done, no errors */
return 0; return 0;
} }
/* Compress len zeros to output. Return -1 on error, 0 on success. */ /* Compress len zeros to output. Return -1 on a write error or memory
local int gz_zero(state, len) allocation failure by gz_comp(), or 0 on success. */
gz_statep state; local int gz_zero(gz_statep state, z_off64_t len) {
z_off64_t len;
{
int first; int first;
unsigned n; unsigned n;
z_streamp strm = &(state->strm); z_streamp strm = &(state->strm);
@ -161,32 +168,10 @@ local int gz_zero(state, len)
return 0; return 0;
} }
/* -- see zlib.h -- */ /* Write len bytes from buf to file. Return the number of bytes written. If
int ZEXPORT gzwrite(file, buf, len) the returned value is less than len, then there was an error. */
gzFile file; local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
voidpc buf; z_size_t put = len;
unsigned len;
{
unsigned put = len;
gz_statep state;
z_streamp strm;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
/* if len is zero, avoid unnecessary operations */ /* if len is zero, avoid unnecessary operations */
if (len == 0) if (len == 0)
@ -209,14 +194,15 @@ int ZEXPORT gzwrite(file, buf, len)
do { do {
unsigned have, copy; unsigned have, copy;
if (strm->avail_in == 0) if (state->strm.avail_in == 0)
strm->next_in = state->in; state->strm.next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in); have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
state->in);
copy = state->size - have; copy = state->size - have;
if (copy > len) if (copy > len)
copy = len; copy = (unsigned)len;
memcpy(state->in + have, buf, copy); memcpy(state->in + have, buf, copy);
strm->avail_in += copy; state->strm.avail_in += copy;
state->x.pos += copy; state->x.pos += copy;
buf = (const char *)buf + copy; buf = (const char *)buf + copy;
len -= copy; len -= copy;
@ -226,26 +212,79 @@ int ZEXPORT gzwrite(file, buf, len)
} }
else { else {
/* consume whatever's left in the input buffer */ /* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return 0; return 0;
/* directly compress user buffer to file */ /* directly compress user buffer to file */
strm->avail_in = len; state->strm.next_in = (z_const Bytef *)buf;
strm->next_in = (z_const Bytef *)buf; do {
state->x.pos += len; unsigned n = (unsigned)-1;
if (gz_comp(state, Z_NO_FLUSH) == -1) if (n > len)
return 0; n = (unsigned)len;
state->strm.avail_in = n;
state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
len -= n;
} while (len);
} }
/* input was all buffered or compressed (put will fit in int) */ /* input was all buffered or compressed */
return (int)put; return put;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputc(file, c) int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) {
gzFile file; gz_statep state;
int c;
{ /* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids a flaw in the interface) */
if ((int)len < 0) {
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
/* write len bytes from buf (the return value will fit in an int) */
return (int)gz_write(state, buf, len);
}
/* -- see zlib.h -- */
z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems,
gzFile file) {
z_size_t len;
gz_statep state;
/* get internal structure */
if (file == NULL)
return 0;
state = (gz_statep)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
/* compute bytes to read -- error on overflow */
len = nitems * size;
if (size && len / size != nitems) {
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
return 0;
}
/* write len bytes to buf, return the number of full items written */
return len ? gz_write(state, buf, len) / size : 0;
}
/* -- see zlib.h -- */
int ZEXPORT gzputc(gzFile file, int c) {
unsigned have; unsigned have;
unsigned char buf[1]; unsigned char buf[1];
gz_statep state; gz_statep state;
@ -275,7 +314,7 @@ int ZEXPORT gzputc(file, c)
strm->next_in = state->in; strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in); have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
if (have < state->size) { if (have < state->size) {
state->in[have] = c; state->in[have] = (unsigned char)c;
strm->avail_in++; strm->avail_in++;
state->x.pos++; state->x.pos++;
return c & 0xff; return c & 0xff;
@ -283,94 +322,112 @@ int ZEXPORT gzputc(file, c)
} }
/* no room in buffer or not initialized, use gz_write() */ /* no room in buffer or not initialized, use gz_write() */
buf[0] = c; buf[0] = (unsigned char)c;
if (gzwrite(file, buf, 1) != 1) if (gz_write(state, buf, 1) != 1)
return -1; return -1;
return c & 0xff; return c & 0xff;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzputs(file, str) int ZEXPORT gzputs(gzFile file, const char *s) {
gzFile file; z_size_t len, put;
const char *str; gz_statep state;
{
int ret; /* get internal structure */
unsigned len; if (file == NULL)
return -1;
state = (gz_statep)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return -1;
/* write string */ /* write string */
len = (unsigned)strlen(str); len = strlen(s);
ret = gzwrite(file, str, len); if ((int)len < 0 || (unsigned)len != len) {
return ret == 0 && len != 0 ? -1 : ret; gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
return -1;
}
put = gz_write(state, s, len);
return put < len ? -1 : (int)len;
} }
#if defined(STDC) || defined(Z_HAVE_STDARG_H) #if defined(STDC) || defined(Z_HAVE_STDARG_H)
#include <stdarg.h> #include <stdarg.h>
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
{ int len;
int size, len; unsigned left;
char *next;
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0; return Z_STREAM_ERROR;
/* make sure we have some buffer space */ /* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return 0; return state->err;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return 0; return state->err;
} }
/* consume whatever's left in the input buffer */ /* do the printf() into the input buffer, put length in len -- the input
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) buffer is double-sized just for this function, so there is guaranteed to
return 0; be state->size bytes available after the current contents */
if (strm->avail_in == 0)
/* do the printf() into the input buffer, put length in len */ strm->next_in = state->in;
size = (int)(state->size); next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
state->in[size - 1] = 0; next[state->size - 1] = 0;
#ifdef NO_vsnprintf #ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void # ifdef HAS_vsprintf_void
(void)vsprintf((char *)(state->in), format, va); (void)vsprintf(next, format, va);
for (len = 0; len < size; len++) for (len = 0; len < state->size; len++)
if (state->in[len] == 0) break; if (next[len] == 0) break;
# else # else
len = vsprintf((char *)(state->in), format, va); len = vsprintf(next, format, va);
# endif # endif
#else #else
# ifdef HAS_vsnprintf_void # ifdef HAS_vsnprintf_void
(void)vsnprintf((char *)(state->in), size, format, va); (void)vsnprintf(next, state->size, format, va);
len = strlen((char *)(state->in)); len = strlen(next);
# else # else
len = vsnprintf((char *)(state->in), size, format, va); len = vsnprintf(next, state->size, format, va);
# endif # endif
#endif #endif
/* check that printf() results fit in buffer */ /* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
return 0; return 0;
/* update buffer and position, defer compression until needed */ /* update buffer and position, compress first half if past that */
strm->avail_in = (unsigned)len; strm->avail_in += (unsigned)len;
strm->next_in = state->in;
state->x.pos += len; state->x.pos += len;
if (strm->avail_in >= state->size) {
left = strm->avail_in - state->size;
strm->avail_in = state->size;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->err;
memmove(state->in, state->in + state->size, left);
strm->next_in = state->in;
strm->avail_in = left;
}
return len; return len;
} }
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
{
va_list va; va_list va;
int ret; int ret;
@ -383,94 +440,97 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
#else /* !STDC && !Z_HAVE_STDARG_H */ #else /* !STDC && !Z_HAVE_STDARG_H */
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) int a4, int a5, int a6, int a7, int a8, int a9, int a10,
gzFile file; int a11, int a12, int a13, int a14, int a15, int a16,
const char *format; int a17, int a18, int a19, int a20) {
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, unsigned len, left;
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; char *next;
{
int size, len;
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
strm = &(state->strm); strm = &(state->strm);
/* check that can really pass pointer in ints */ /* check that can really pass pointer in ints */
if (sizeof(int) != sizeof(void *)) if (sizeof(int) != sizeof(void *))
return 0; return Z_STREAM_ERROR;
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0; return Z_STREAM_ERROR;
/* make sure we have some buffer space */ /* make sure we have some buffer space */
if (state->size == 0 && gz_init(state) == -1) if (state->size == 0 && gz_init(state) == -1)
return 0; return state->error;
/* check for seek request */ /* check for seek request */
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return 0; return state->error;
} }
/* consume whatever's left in the input buffer */ /* do the printf() into the input buffer, put length in len -- the input
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) buffer is double-sized just for this function, so there is guaranteed to
return 0; be state->size bytes available after the current contents */
if (strm->avail_in == 0)
/* do the printf() into the input buffer, put length in len */ strm->next_in = state->in;
size = (int)(state->size); next = (char *)(strm->next_in + strm->avail_in);
state->in[size - 1] = 0; next[state->size - 1] = 0;
#ifdef NO_snprintf #ifdef NO_snprintf
# ifdef HAS_sprintf_void # ifdef HAS_sprintf_void
sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a13, a14, a15, a16, a17, a18, a19, a20);
for (len = 0; len < size; len++) for (len = 0; len < size; len++)
if (state->in[len] == 0) break; if (next[len] == 0)
break;
# else # else
len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a12, a13, a14, a15, a16, a17, a18, a19, a20);
# endif # endif
#else #else
# ifdef HAS_snprintf_void # ifdef HAS_snprintf_void
snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8, snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
len = strlen((char *)(state->in)); len = strlen(next);
# else # else
len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
a19, a20);
# endif # endif
#endif #endif
/* check that printf() results fit in buffer */ /* check that printf() results fit in buffer */
if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) if (len == 0 || len >= state->size || next[state->size - 1] != 0)
return 0; return 0;
/* update buffer and position, defer compression until needed */ /* update buffer and position, compress first half if past that */
strm->avail_in = (unsigned)len; strm->avail_in += len;
strm->next_in = state->in;
state->x.pos += len; state->x.pos += len;
return len; if (strm->avail_in >= state->size) {
left = strm->avail_in - state->size;
strm->avail_in = state->size;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return state->err;
memmove(state->in, state->in + state->size, left);
strm->next_in = state->in;
strm->avail_in = left;
}
return (int)len;
} }
#endif #endif
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzflush(file, flush) int ZEXPORT gzflush(gzFile file, int flush) {
gzFile file;
int flush;
{
gz_statep state; gz_statep state;
/* get internal structure */ /* get internal structure */
if (file == NULL) if (file == NULL)
return -1; return Z_STREAM_ERROR;
state = (gz_statep)file; state = (gz_statep)file;
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
@ -485,20 +545,16 @@ int ZEXPORT gzflush(file, flush)
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return -1; return state->err;
} }
/* compress remaining data with requested flush */ /* compress remaining data with requested flush */
gz_comp(state, flush); (void)gz_comp(state, flush);
return state->err; return state->err;
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzsetparams(file, level, strategy) int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
gzFile file;
int level;
int strategy;
{
gz_statep state; gz_statep state;
z_streamp strm; z_streamp strm;
@ -509,7 +565,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
strm = &(state->strm); strm = &(state->strm);
/* check that we're writing and that there's no error */ /* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK) if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
/* if no change is requested, then do nothing */ /* if no change is requested, then do nothing */
@ -520,13 +576,13 @@ int ZEXPORT gzsetparams(file, level, strategy)
if (state->seek) { if (state->seek) {
state->seek = 0; state->seek = 0;
if (gz_zero(state, state->skip) == -1) if (gz_zero(state, state->skip) == -1)
return -1; return state->err;
} }
/* change compression parameters for subsequent input */ /* change compression parameters for subsequent input */
if (state->size) { if (state->size) {
/* flush previous input with previous parameters before changing */ /* flush previous input with previous parameters before changing */
if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
return state->err; return state->err;
deflateParams(strm, level, strategy); deflateParams(strm, level, strategy);
} }
@ -536,9 +592,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
} }
/* -- see zlib.h -- */ /* -- see zlib.h -- */
int ZEXPORT gzclose_w(file) int ZEXPORT gzclose_w(gzFile file) {
gzFile file;
{
int ret = Z_OK; int ret = Z_OK;
gz_statep state; gz_statep state;

View file

@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface /* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2011 Mark Adler * Copyright (C) 1995-2022 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -15,9 +15,6 @@
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
/* function prototypes */
local void fixedtables OF((struct inflate_state FAR *state));
/* /*
strm provides memory allocation functions in zalloc and zfree, or strm provides memory allocation functions in zalloc and zfree, or
Z_NULL to use the library memory allocation functions. Z_NULL to use the library memory allocation functions.
@ -25,13 +22,9 @@ local void fixedtables OF((struct inflate_state FAR *state));
windowBits is in the range 8..15, and window is a user-supplied windowBits is in the range 8..15, and window is a user-supplied
window and output buffer that is 2**windowBits bytes. window and output buffer that is 2**windowBits bytes.
*/ */
int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits,
z_streamp strm; unsigned char FAR *window, const char *version,
int windowBits; int stream_size) {
unsigned char FAR *window;
const char *version;
int stream_size;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
@ -61,11 +54,12 @@ int stream_size;
Tracev((stderr, "inflate: allocated\n")); Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state; strm->state = (struct internal_state FAR *)state;
state->dmax = 32768U; state->dmax = 32768U;
state->wbits = windowBits; state->wbits = (uInt)windowBits;
state->wsize = 1U << windowBits; state->wsize = 1U << windowBits;
state->window = window; state->window = window;
state->wnext = 0; state->wnext = 0;
state->whave = 0; state->whave = 0;
state->sane = 1;
return Z_OK; return Z_OK;
} }
@ -79,9 +73,7 @@ int stream_size;
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(state) local void fixedtables(struct inflate_state FAR *state) {
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
@ -247,13 +239,8 @@ struct inflate_state FAR *state;
inflateBack() can also return Z_STREAM_ERROR if the input parameters inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized. are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/ */
int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
z_streamp strm; out_func out, void FAR *out_desc) {
in_func in;
void FAR *in_desc;
out_func out;
void FAR *out_desc;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
@ -477,6 +464,7 @@ void FAR *out_desc;
} }
Tracev((stderr, "inflate: codes ok\n")); Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN; state->mode = LEN;
/* fallthrough */
case LEN: case LEN:
/* use inflate_fast() if we have enough input and output */ /* use inflate_fast() if we have enough input and output */
@ -604,33 +592,33 @@ void FAR *out_desc;
break; break;
case DONE: case DONE:
/* inflate stream terminated properly -- write leftover output */ /* inflate stream terminated properly */
ret = Z_STREAM_END; ret = Z_STREAM_END;
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left))
ret = Z_BUF_ERROR;
}
goto inf_leave; goto inf_leave;
case BAD: case BAD:
ret = Z_DATA_ERROR; ret = Z_DATA_ERROR;
goto inf_leave; goto inf_leave;
default: /* can't happen, but makes compilers happy */ default:
/* can't happen, but makes compilers happy */
ret = Z_STREAM_ERROR; ret = Z_STREAM_ERROR;
goto inf_leave; goto inf_leave;
} }
/* Return unused input */ /* Write leftover output and return unused input */
inf_leave: inf_leave:
if (left < state->wsize) {
if (out(out_desc, state->window, state->wsize - left) &&
ret == Z_STREAM_END)
ret = Z_BUF_ERROR;
}
strm->next_in = next; strm->next_in = next;
strm->avail_in = have; strm->avail_in = have;
return ret; return ret;
} }
int ZEXPORT inflateBackEnd(strm) int ZEXPORT inflateBackEnd(z_streamp strm) {
z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
ZFREE(strm, strm->state); ZFREE(strm, strm->state);

View file

@ -1,5 +1,5 @@
/* inffast.c -- fast decoding /* inffast.c -- fast decoding
* Copyright (C) 1995-2008, 2010, 2013 Mark Adler * Copyright (C) 1995-2017 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -8,26 +8,9 @@
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
#ifndef ASMINF #ifdef ASMINF
# pragma message("Assembler code may have bugs -- use at your own risk")
/* Allow machine dependent optimization for post-increment or pre-increment.
Based on testing to date,
Pre-increment preferred for:
- PowerPC G3 (Adler)
- MIPS R5000 (Randers-Pehrson)
Post-increment preferred for:
- none
No measurable difference:
- Pentium III (Anderson)
- M68060 (Nikl)
*/
#ifdef POSTINC
# define OFF 0
# define PUP(a) *(a)++
#else #else
# define OFF 1
# define PUP(a) *++(a)
#endif
/* /*
Decode literal, length, and distance codes and write out the resulting Decode literal, length, and distance codes and write out the resulting
@ -64,10 +47,7 @@
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void ZLIB_INTERNAL inflate_fast(strm, start) void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *in; /* local strm->next_in */
z_const unsigned char FAR *last; /* have enough input while in < last */ z_const unsigned char FAR *last; /* have enough input while in < last */
@ -87,7 +67,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
code const FAR *dcode; /* local strm->distcode */ code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */ unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */ unsigned dmask; /* mask for first level of distance codes */
code here; /* retrieved table entry */ code const *here; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */ unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */ /* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */ unsigned len; /* match length, unused bytes */
@ -96,9 +76,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
/* copy state to local variables */ /* copy state to local variables */
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF; in = strm->next_in;
last = in + (strm->avail_in - 5); last = in + (strm->avail_in - 5);
out = strm->next_out - OFF; out = strm->next_out;
beg = out - (start - strm->avail_out); beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257); end = out + (strm->avail_out - 257);
#ifdef INFLATE_STRICT #ifdef INFLATE_STRICT
@ -119,29 +99,29 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
input data or output space */ input data or output space */
do { do {
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = lcode[hold & lmask]; here = lcode + (hold & lmask);
dolen: dolen:
op = (unsigned)(here.bits); op = (unsigned)(here->bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here->op);
if (op == 0) { /* literal */ if (op == 0) { /* literal */
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val)); "inflate: literal 0x%02x\n", here->val));
PUP(out) = (unsigned char)(here.val); *out++ = (unsigned char)(here->val);
} }
else if (op & 16) { /* length base */ else if (op & 16) { /* length base */
len = (unsigned)(here.val); len = (unsigned)(here->val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) { if (op) {
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
len += (unsigned)hold & ((1U << op) - 1); len += (unsigned)hold & ((1U << op) - 1);
@ -150,25 +130,25 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
} }
Tracevv((stderr, "inflate: length %u\n", len)); Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
here = dcode[hold & dmask]; here = dcode + (hold & dmask);
dodist: dodist:
op = (unsigned)(here.bits); op = (unsigned)(here->bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(here.op); op = (unsigned)(here->op);
if (op & 16) { /* distance base */ if (op & 16) { /* distance base */
dist = (unsigned)(here.val); dist = (unsigned)(here->val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(*in++) << bits;
bits += 8; bits += 8;
} }
} }
@ -196,30 +176,30 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
if (len <= op - whave) { if (len <= op - whave) {
do { do {
PUP(out) = 0; *out++ = 0;
} while (--len); } while (--len);
continue; continue;
} }
len -= op - whave; len -= op - whave;
do { do {
PUP(out) = 0; *out++ = 0;
} while (--op > whave); } while (--op > whave);
if (op == 0) { if (op == 0) {
from = out - dist; from = out - dist;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--len); } while (--len);
continue; continue;
} }
#endif #endif
} }
from = window - OFF; from = window;
if (wnext == 0) { /* very common case */ if (wnext == 0) { /* very common case */
from += wsize - op; from += wsize - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
@ -230,14 +210,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
if (op < len) { /* some from end of window */ if (op < len) { /* some from end of window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = window - OFF; from = window;
if (wnext < len) { /* some from start of window */ if (wnext < len) { /* some from start of window */
op = wnext; op = wnext;
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
@ -248,40 +228,40 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); *out++ = *from++;
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
while (len > 2) { while (len > 2) {
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
len -= 3; len -= 3;
} }
if (len) { if (len) {
PUP(out) = PUP(from); *out++ = *from++;
if (len > 1) if (len > 1)
PUP(out) = PUP(from); *out++ = *from++;
} }
} }
else { else {
from = out - dist; /* copy direct from output */ from = out - dist; /* copy direct from output */
do { /* minimum length is three */ do { /* minimum length is three */
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
PUP(out) = PUP(from); *out++ = *from++;
len -= 3; len -= 3;
} while (len > 2); } while (len > 2);
if (len) { if (len) {
PUP(out) = PUP(from); *out++ = *from++;
if (len > 1) if (len > 1)
PUP(out) = PUP(from); *out++ = *from++;
} }
} }
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else if ((op & 64) == 0) { /* 2nd level distance code */
here = dcode[here.val + (hold & ((1U << op) - 1))]; here = dcode + here->val + (hold & ((1U << op) - 1));
goto dodist; goto dodist;
} }
else { else {
@ -291,7 +271,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
} }
} }
else if ((op & 64) == 0) { /* 2nd level length code */ else if ((op & 64) == 0) { /* 2nd level length code */
here = lcode[here.val + (hold & ((1U << op) - 1))]; here = lcode + here->val + (hold & ((1U << op) - 1));
goto dolen; goto dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) { /* end-of-block */
@ -313,8 +293,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold &= (1U << bits) - 1; hold &= (1U << bits) - 1;
/* update state and return */ /* update state and return */
strm->next_in = in + OFF; strm->next_in = in;
strm->next_out = out + OFF; strm->next_out = out;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ? strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end)); 257 + (end - out) : 257 - (out - end));

View file

@ -8,4 +8,4 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);

View file

@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression /* inflate.c -- zlib decompression
* Copyright (C) 1995-2012 Mark Adler * Copyright (C) 1995-2022 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -91,22 +91,22 @@
# endif # endif
#endif #endif
/* function prototypes */ local int inflateStateCheck(z_streamp strm) {
local void fixedtables OF((struct inflate_state FAR *state)); struct inflate_state FAR *state;
local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, if (strm == Z_NULL ||
unsigned copy)); strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
#ifdef BUILDFIXED return 1;
void makefixed OF((void)); state = (struct inflate_state FAR *)strm->state;
#endif if (state == Z_NULL || state->strm != strm ||
local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, state->mode < HEAD || state->mode > SYNC)
unsigned len)); return 1;
return 0;
}
int ZEXPORT inflateResetKeep(strm) int ZEXPORT inflateResetKeep(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
strm->total_in = strm->total_out = state->total = 0; strm->total_in = strm->total_out = state->total = 0;
strm->msg = Z_NULL; strm->msg = Z_NULL;
@ -115,6 +115,7 @@ z_streamp strm;
state->mode = HEAD; state->mode = HEAD;
state->last = 0; state->last = 0;
state->havedict = 0; state->havedict = 0;
state->flags = -1;
state->dmax = 32768U; state->dmax = 32768U;
state->head = Z_NULL; state->head = Z_NULL;
state->hold = 0; state->hold = 0;
@ -126,12 +127,10 @@ z_streamp strm;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateReset(strm) int ZEXPORT inflateReset(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
state->wsize = 0; state->wsize = 0;
state->whave = 0; state->whave = 0;
@ -139,24 +138,23 @@ z_streamp strm;
return inflateResetKeep(strm); return inflateResetKeep(strm);
} }
int ZEXPORT inflateReset2(strm, windowBits) int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
z_streamp strm;
int windowBits;
{
int wrap; int wrap;
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* get the state */ /* get the state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
/* extract wrap request from windowBits parameter */ /* extract wrap request from windowBits parameter */
if (windowBits < 0) { if (windowBits < 0) {
if (windowBits < -15)
return Z_STREAM_ERROR;
wrap = 0; wrap = 0;
windowBits = -windowBits; windowBits = -windowBits;
} }
else { else {
wrap = (windowBits >> 4) + 1; wrap = (windowBits >> 4) + 5;
#ifdef GUNZIP #ifdef GUNZIP
if (windowBits < 48) if (windowBits < 48)
windowBits &= 15; windowBits &= 15;
@ -177,12 +175,8 @@ int windowBits;
return inflateReset(strm); return inflateReset(strm);
} }
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) int ZEXPORT inflateInit2_(z_streamp strm, int windowBits,
z_streamp strm; const char *version, int stream_size) {
int windowBits;
const char *version;
int stream_size;
{
int ret; int ret;
struct inflate_state FAR *state; struct inflate_state FAR *state;
@ -210,7 +204,9 @@ int stream_size;
if (state == Z_NULL) return Z_MEM_ERROR; if (state == Z_NULL) return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n")); Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state; strm->state = (struct internal_state FAR *)state;
state->strm = strm;
state->window = Z_NULL; state->window = Z_NULL;
state->mode = HEAD; /* to pass state test in inflateReset2() */
ret = inflateReset2(strm, windowBits); ret = inflateReset2(strm, windowBits);
if (ret != Z_OK) { if (ret != Z_OK) {
ZFREE(strm, state); ZFREE(strm, state);
@ -219,32 +215,27 @@ int stream_size;
return ret; return ret;
} }
int ZEXPORT inflateInit_(strm, version, stream_size) int ZEXPORT inflateInit_(z_streamp strm, const char *version,
z_streamp strm; int stream_size) {
const char *version;
int stream_size;
{
return inflateInit2_(strm, DEF_WBITS, version, stream_size); return inflateInit2_(strm, DEF_WBITS, version, stream_size);
} }
int ZEXPORT inflatePrime(strm, bits, value) int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) {
z_streamp strm;
int bits;
int value;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
if (bits == 0)
return Z_OK;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (bits < 0) { if (bits < 0) {
state->hold = 0; state->hold = 0;
state->bits = 0; state->bits = 0;
return Z_OK; return Z_OK;
} }
if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
value &= (1L << bits) - 1; value &= (1L << bits) - 1;
state->hold += value << state->bits; state->hold += (unsigned)value << state->bits;
state->bits += bits; state->bits += (uInt)bits;
return Z_OK; return Z_OK;
} }
@ -258,9 +249,7 @@ int value;
used for threaded applications, since the rewriting of the tables and virgin used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe. may not be thread-safe.
*/ */
local void fixedtables(state) local void fixedtables(struct inflate_state FAR *state) {
struct inflate_state FAR *state;
{
#ifdef BUILDFIXED #ifdef BUILDFIXED
static int virgin = 1; static int virgin = 1;
static code *lenfix, *distfix; static code *lenfix, *distfix;
@ -322,7 +311,7 @@ struct inflate_state FAR *state;
a.out > inffixed.h a.out > inffixed.h
*/ */
void makefixed() void makefixed(void)
{ {
unsigned low, size; unsigned low, size;
struct inflate_state state; struct inflate_state state;
@ -376,11 +365,7 @@ void makefixed()
output will fall in the output data, making match copies simpler and faster. output will fall in the output data, making match copies simpler and faster.
The advantage may be dependent on the size of the processor's data caches. The advantage may be dependent on the size of the processor's data caches.
*/ */
local int updatewindow(strm, end, copy) local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) {
z_streamp strm;
const Bytef *end;
unsigned copy;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned dist; unsigned dist;
@ -430,10 +415,10 @@ unsigned copy;
/* check function to use adler32() for zlib or crc32() for gzip */ /* check function to use adler32() for zlib or crc32() for gzip */
#ifdef GUNZIP #ifdef GUNZIP
# define UPDATE(check, buf, len) \ # define UPDATE_CHECK(check, buf, len) \
(state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
#else #else
# define UPDATE(check, buf, len) adler32(check, buf, len) # define UPDATE_CHECK(check, buf, len) adler32(check, buf, len)
#endif #endif
/* check macros for header crc */ /* check macros for header crc */
@ -602,10 +587,7 @@ unsigned copy;
will return Z_BUF_ERROR if it has not reached the end of the stream. will return Z_BUF_ERROR if it has not reached the end of the stream.
*/ */
int ZEXPORT inflate(strm, flush) int ZEXPORT inflate(z_streamp strm, int flush) {
z_streamp strm;
int flush;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
z_const unsigned char FAR *next; /* next input */ z_const unsigned char FAR *next; /* next input */
unsigned char FAR *put; /* next output */ unsigned char FAR *put; /* next output */
@ -625,7 +607,7 @@ int flush;
static const unsigned short order[19] = /* permutation of code lengths */ static const unsigned short order[19] = /* permutation of code lengths */
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
(strm->next_in == Z_NULL && strm->avail_in != 0)) (strm->next_in == Z_NULL && strm->avail_in != 0))
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
@ -645,13 +627,14 @@ int flush;
NEEDBITS(16); NEEDBITS(16);
#ifdef GUNZIP #ifdef GUNZIP
if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
if (state->wbits == 0)
state->wbits = 15;
state->check = crc32(0L, Z_NULL, 0); state->check = crc32(0L, Z_NULL, 0);
CRC2(state->check, hold); CRC2(state->check, hold);
INITBITS(); INITBITS();
state->mode = FLAGS; state->mode = FLAGS;
break; break;
} }
state->flags = 0; /* expect zlib header */
if (state->head != Z_NULL) if (state->head != Z_NULL)
state->head->done = -1; state->head->done = -1;
if (!(state->wrap & 1) || /* check if zlib header allowed */ if (!(state->wrap & 1) || /* check if zlib header allowed */
@ -672,12 +655,13 @@ int flush;
len = BITS(4) + 8; len = BITS(4) + 8;
if (state->wbits == 0) if (state->wbits == 0)
state->wbits = len; state->wbits = len;
else if (len > state->wbits) { if (len > 15 || len > state->wbits) {
strm->msg = (char *)"invalid window size"; strm->msg = (char *)"invalid window size";
state->mode = BAD; state->mode = BAD;
break; break;
} }
state->dmax = 1U << len; state->dmax = 1U << len;
state->flags = 0; /* indicate zlib header */
Tracev((stderr, "inflate: zlib header ok\n")); Tracev((stderr, "inflate: zlib header ok\n"));
strm->adler = state->check = adler32(0L, Z_NULL, 0); strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = hold & 0x200 ? DICTID : TYPE; state->mode = hold & 0x200 ? DICTID : TYPE;
@ -699,50 +683,59 @@ int flush;
} }
if (state->head != Z_NULL) if (state->head != Z_NULL)
state->head->text = (int)((hold >> 8) & 1); state->head->text = (int)((hold >> 8) & 1);
if (state->flags & 0x0200) CRC2(state->check, hold); if ((state->flags & 0x0200) && (state->wrap & 4))
CRC2(state->check, hold);
INITBITS(); INITBITS();
state->mode = TIME; state->mode = TIME;
/* fallthrough */
case TIME: case TIME:
NEEDBITS(32); NEEDBITS(32);
if (state->head != Z_NULL) if (state->head != Z_NULL)
state->head->time = hold; state->head->time = hold;
if (state->flags & 0x0200) CRC4(state->check, hold); if ((state->flags & 0x0200) && (state->wrap & 4))
CRC4(state->check, hold);
INITBITS(); INITBITS();
state->mode = OS; state->mode = OS;
/* fallthrough */
case OS: case OS:
NEEDBITS(16); NEEDBITS(16);
if (state->head != Z_NULL) { if (state->head != Z_NULL) {
state->head->xflags = (int)(hold & 0xff); state->head->xflags = (int)(hold & 0xff);
state->head->os = (int)(hold >> 8); state->head->os = (int)(hold >> 8);
} }
if (state->flags & 0x0200) CRC2(state->check, hold); if ((state->flags & 0x0200) && (state->wrap & 4))
CRC2(state->check, hold);
INITBITS(); INITBITS();
state->mode = EXLEN; state->mode = EXLEN;
/* fallthrough */
case EXLEN: case EXLEN:
if (state->flags & 0x0400) { if (state->flags & 0x0400) {
NEEDBITS(16); NEEDBITS(16);
state->length = (unsigned)(hold); state->length = (unsigned)(hold);
if (state->head != Z_NULL) if (state->head != Z_NULL)
state->head->extra_len = (unsigned)hold; state->head->extra_len = (unsigned)hold;
if (state->flags & 0x0200) CRC2(state->check, hold); if ((state->flags & 0x0200) && (state->wrap & 4))
CRC2(state->check, hold);
INITBITS(); INITBITS();
} }
else if (state->head != Z_NULL) else if (state->head != Z_NULL)
state->head->extra = Z_NULL; state->head->extra = Z_NULL;
state->mode = EXTRA; state->mode = EXTRA;
/* fallthrough */
case EXTRA: case EXTRA:
if (state->flags & 0x0400) { if (state->flags & 0x0400) {
copy = state->length; copy = state->length;
if (copy > have) copy = have; if (copy > have) copy = have;
if (copy) { if (copy) {
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->extra != Z_NULL) { state->head->extra != Z_NULL &&
len = state->head->extra_len - state->length; (len = state->head->extra_len - state->length) <
state->head->extra_max) {
zmemcpy(state->head->extra + len, next, zmemcpy(state->head->extra + len, next,
len + copy > state->head->extra_max ? len + copy > state->head->extra_max ?
state->head->extra_max - len : copy); state->head->extra_max - len : copy);
} }
if (state->flags & 0x0200) if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy); state->check = crc32(state->check, next, copy);
have -= copy; have -= copy;
next += copy; next += copy;
@ -752,6 +745,7 @@ int flush;
} }
state->length = 0; state->length = 0;
state->mode = NAME; state->mode = NAME;
/* fallthrough */
case NAME: case NAME:
if (state->flags & 0x0800) { if (state->flags & 0x0800) {
if (have == 0) goto inf_leave; if (have == 0) goto inf_leave;
@ -761,9 +755,9 @@ int flush;
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->name != Z_NULL && state->head->name != Z_NULL &&
state->length < state->head->name_max) state->length < state->head->name_max)
state->head->name[state->length++] = len; state->head->name[state->length++] = (Bytef)len;
} while (len && copy < have); } while (len && copy < have);
if (state->flags & 0x0200) if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy); state->check = crc32(state->check, next, copy);
have -= copy; have -= copy;
next += copy; next += copy;
@ -773,6 +767,7 @@ int flush;
state->head->name = Z_NULL; state->head->name = Z_NULL;
state->length = 0; state->length = 0;
state->mode = COMMENT; state->mode = COMMENT;
/* fallthrough */
case COMMENT: case COMMENT:
if (state->flags & 0x1000) { if (state->flags & 0x1000) {
if (have == 0) goto inf_leave; if (have == 0) goto inf_leave;
@ -782,9 +777,9 @@ int flush;
if (state->head != Z_NULL && if (state->head != Z_NULL &&
state->head->comment != Z_NULL && state->head->comment != Z_NULL &&
state->length < state->head->comm_max) state->length < state->head->comm_max)
state->head->comment[state->length++] = len; state->head->comment[state->length++] = (Bytef)len;
} while (len && copy < have); } while (len && copy < have);
if (state->flags & 0x0200) if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy); state->check = crc32(state->check, next, copy);
have -= copy; have -= copy;
next += copy; next += copy;
@ -793,10 +788,11 @@ int flush;
else if (state->head != Z_NULL) else if (state->head != Z_NULL)
state->head->comment = Z_NULL; state->head->comment = Z_NULL;
state->mode = HCRC; state->mode = HCRC;
/* fallthrough */
case HCRC: case HCRC:
if (state->flags & 0x0200) { if (state->flags & 0x0200) {
NEEDBITS(16); NEEDBITS(16);
if (hold != (state->check & 0xffff)) { if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
strm->msg = (char *)"header crc mismatch"; strm->msg = (char *)"header crc mismatch";
state->mode = BAD; state->mode = BAD;
break; break;
@ -816,6 +812,7 @@ int flush;
strm->adler = state->check = ZSWAP32(hold); strm->adler = state->check = ZSWAP32(hold);
INITBITS(); INITBITS();
state->mode = DICT; state->mode = DICT;
/* fallthrough */
case DICT: case DICT:
if (state->havedict == 0) { if (state->havedict == 0) {
RESTORE(); RESTORE();
@ -823,8 +820,10 @@ int flush;
} }
strm->adler = state->check = adler32(0L, Z_NULL, 0); strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = TYPE; state->mode = TYPE;
/* fallthrough */
case TYPE: case TYPE:
if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
/* fallthrough */
case TYPEDO: case TYPEDO:
if (state->last) { if (state->last) {
BYTEBITS(); BYTEBITS();
@ -875,8 +874,10 @@ int flush;
INITBITS(); INITBITS();
state->mode = COPY_; state->mode = COPY_;
if (flush == Z_TREES) goto inf_leave; if (flush == Z_TREES) goto inf_leave;
/* fallthrough */
case COPY_: case COPY_:
state->mode = COPY; state->mode = COPY;
/* fallthrough */
case COPY: case COPY:
copy = state->length; copy = state->length;
if (copy) { if (copy) {
@ -912,6 +913,7 @@ int flush;
Tracev((stderr, "inflate: table sizes ok\n")); Tracev((stderr, "inflate: table sizes ok\n"));
state->have = 0; state->have = 0;
state->mode = LENLENS; state->mode = LENLENS;
/* fallthrough */
case LENLENS: case LENLENS:
while (state->have < state->ncode) { while (state->have < state->ncode) {
NEEDBITS(3); NEEDBITS(3);
@ -933,6 +935,7 @@ int flush;
Tracev((stderr, "inflate: code lengths ok\n")); Tracev((stderr, "inflate: code lengths ok\n"));
state->have = 0; state->have = 0;
state->mode = CODELENS; state->mode = CODELENS;
/* fallthrough */
case CODELENS: case CODELENS:
while (state->have < state->nlen + state->ndist) { while (state->have < state->nlen + state->ndist) {
for (;;) { for (;;) {
@ -1016,8 +1019,10 @@ int flush;
Tracev((stderr, "inflate: codes ok\n")); Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN_; state->mode = LEN_;
if (flush == Z_TREES) goto inf_leave; if (flush == Z_TREES) goto inf_leave;
/* fallthrough */
case LEN_: case LEN_:
state->mode = LEN; state->mode = LEN;
/* fallthrough */
case LEN: case LEN:
if (have >= 6 && left >= 258) { if (have >= 6 && left >= 258) {
RESTORE(); RESTORE();
@ -1067,6 +1072,7 @@ int flush;
} }
state->extra = (unsigned)(here.op) & 15; state->extra = (unsigned)(here.op) & 15;
state->mode = LENEXT; state->mode = LENEXT;
/* fallthrough */
case LENEXT: case LENEXT:
if (state->extra) { if (state->extra) {
NEEDBITS(state->extra); NEEDBITS(state->extra);
@ -1077,6 +1083,7 @@ int flush;
Tracevv((stderr, "inflate: length %u\n", state->length)); Tracevv((stderr, "inflate: length %u\n", state->length));
state->was = state->length; state->was = state->length;
state->mode = DIST; state->mode = DIST;
/* fallthrough */
case DIST: case DIST:
for (;;) { for (;;) {
here = state->distcode[BITS(state->distbits)]; here = state->distcode[BITS(state->distbits)];
@ -1104,6 +1111,7 @@ int flush;
state->offset = (unsigned)here.val; state->offset = (unsigned)here.val;
state->extra = (unsigned)(here.op) & 15; state->extra = (unsigned)(here.op) & 15;
state->mode = DISTEXT; state->mode = DISTEXT;
/* fallthrough */
case DISTEXT: case DISTEXT:
if (state->extra) { if (state->extra) {
NEEDBITS(state->extra); NEEDBITS(state->extra);
@ -1120,6 +1128,7 @@ int flush;
#endif #endif
Tracevv((stderr, "inflate: distance %u\n", state->offset)); Tracevv((stderr, "inflate: distance %u\n", state->offset));
state->mode = MATCH; state->mode = MATCH;
/* fallthrough */
case MATCH: case MATCH:
if (left == 0) goto inf_leave; if (left == 0) goto inf_leave;
copy = out - left; copy = out - left;
@ -1177,11 +1186,11 @@ int flush;
out -= left; out -= left;
strm->total_out += out; strm->total_out += out;
state->total += out; state->total += out;
if (out) if ((state->wrap & 4) && out)
strm->adler = state->check = strm->adler = state->check =
UPDATE(state->check, put - out, out); UPDATE_CHECK(state->check, put - out, out);
out = left; out = left;
if (( if ((state->wrap & 4) && (
#ifdef GUNZIP #ifdef GUNZIP
state->flags ? hold : state->flags ? hold :
#endif #endif
@ -1195,10 +1204,11 @@ int flush;
} }
#ifdef GUNZIP #ifdef GUNZIP
state->mode = LENGTH; state->mode = LENGTH;
/* fallthrough */
case LENGTH: case LENGTH:
if (state->wrap && state->flags) { if (state->wrap && state->flags) {
NEEDBITS(32); NEEDBITS(32);
if (hold != (state->total & 0xffffffffUL)) { if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
strm->msg = (char *)"incorrect length check"; strm->msg = (char *)"incorrect length check";
state->mode = BAD; state->mode = BAD;
break; break;
@ -1208,6 +1218,7 @@ int flush;
} }
#endif #endif
state->mode = DONE; state->mode = DONE;
/* fallthrough */
case DONE: case DONE:
ret = Z_STREAM_END; ret = Z_STREAM_END;
goto inf_leave; goto inf_leave;
@ -1217,6 +1228,7 @@ int flush;
case MEM: case MEM:
return Z_MEM_ERROR; return Z_MEM_ERROR;
case SYNC: case SYNC:
/* fallthrough */
default: default:
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
} }
@ -1240,10 +1252,10 @@ int flush;
strm->total_in += in; strm->total_in += in;
strm->total_out += out; strm->total_out += out;
state->total += out; state->total += out;
if (state->wrap && out) if ((state->wrap & 4) && out)
strm->adler = state->check = strm->adler = state->check =
UPDATE(state->check, strm->next_out - out, out); UPDATE_CHECK(state->check, strm->next_out - out, out);
strm->data_type = state->bits + (state->last ? 64 : 0) + strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
(state->mode == TYPE ? 128 : 0) + (state->mode == TYPE ? 128 : 0) +
(state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
@ -1251,11 +1263,9 @@ int flush;
return ret; return ret;
} }
int ZEXPORT inflateEnd(strm) int ZEXPORT inflateEnd(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) if (inflateStateCheck(strm))
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (state->window != Z_NULL) ZFREE(strm, state->window); if (state->window != Z_NULL) ZFREE(strm, state->window);
@ -1265,15 +1275,12 @@ z_streamp strm;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary,
z_streamp strm; uInt *dictLength) {
Bytef *dictionary;
uInt *dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
/* copy dictionary */ /* copy dictionary */
@ -1288,17 +1295,14 @@ uInt *dictLength;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
z_streamp strm; uInt dictLength) {
const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned long dictid; unsigned long dictid;
int ret; int ret;
/* check state */ /* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (state->wrap != 0 && state->mode != DICT) if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
@ -1323,14 +1327,11 @@ uInt dictLength;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateGetHeader(strm, head) int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) {
z_streamp strm;
gz_headerp head;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check state */ /* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
@ -1351,11 +1352,8 @@ gz_headerp head;
called again with more data and the *have state. *have is initialized to called again with more data and the *have state. *have is initialized to
zero for the first call. zero for the first call.
*/ */
local unsigned syncsearch(have, buf, len) local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf,
unsigned FAR *have; unsigned len) {
const unsigned char FAR *buf;
unsigned len;
{
unsigned got; unsigned got;
unsigned next; unsigned next;
@ -1374,23 +1372,22 @@ unsigned len;
return next; return next;
} }
int ZEXPORT inflateSync(strm) int ZEXPORT inflateSync(z_streamp strm) {
z_streamp strm;
{
unsigned len; /* number of bytes to look at or looked at */ unsigned len; /* number of bytes to look at or looked at */
int flags; /* temporary to save header status */
unsigned long in, out; /* temporary to save total_in and total_out */ unsigned long in, out; /* temporary to save total_in and total_out */
unsigned char buf[4]; /* to restore bit buffer to byte string */ unsigned char buf[4]; /* to restore bit buffer to byte string */
struct inflate_state FAR *state; struct inflate_state FAR *state;
/* check parameters */ /* check parameters */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
/* if first time, start search in bit buffer */ /* if first time, start search in bit buffer */
if (state->mode != SYNC) { if (state->mode != SYNC) {
state->mode = SYNC; state->mode = SYNC;
state->hold <<= state->bits & 7; state->hold >>= state->bits & 7;
state->bits -= state->bits & 7; state->bits -= state->bits & 7;
len = 0; len = 0;
while (state->bits >= 8) { while (state->bits >= 8) {
@ -1410,9 +1407,15 @@ z_streamp strm;
/* return no joy or set up to restart inflate() on a new block */ /* return no joy or set up to restart inflate() on a new block */
if (state->have != 4) return Z_DATA_ERROR; if (state->have != 4) return Z_DATA_ERROR;
if (state->flags == -1)
state->wrap = 0; /* if no header yet, treat as raw */
else
state->wrap &= ~4; /* no point in computing a check value now */
flags = state->flags;
in = strm->total_in; out = strm->total_out; in = strm->total_in; out = strm->total_out;
inflateReset(strm); inflateReset(strm);
strm->total_in = in; strm->total_out = out; strm->total_in = in; strm->total_out = out;
state->flags = flags;
state->mode = TYPE; state->mode = TYPE;
return Z_OK; return Z_OK;
} }
@ -1425,28 +1428,22 @@ z_streamp strm;
block. When decompressing, PPP checks that at the end of input packet, block. When decompressing, PPP checks that at the end of input packet,
inflate is waiting for these length bytes. inflate is waiting for these length bytes.
*/ */
int ZEXPORT inflateSyncPoint(strm) int ZEXPORT inflateSyncPoint(z_streamp strm) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
return state->mode == STORED && state->bits == 0; return state->mode == STORED && state->bits == 0;
} }
int ZEXPORT inflateCopy(dest, source) int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
z_streamp dest;
z_streamp source;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
struct inflate_state FAR *copy; struct inflate_state FAR *copy;
unsigned char FAR *window; unsigned char FAR *window;
unsigned wsize; unsigned wsize;
/* check input */ /* check input */
if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || if (inflateStateCheck(source) || dest == Z_NULL)
source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)source->state; state = (struct inflate_state FAR *)source->state;
@ -1467,6 +1464,7 @@ z_streamp source;
/* copy state */ /* copy state */
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
copy->strm = dest;
if (state->lencode >= state->codes && if (state->lencode >= state->codes &&
state->lencode <= state->codes + ENOUGH - 1) { state->lencode <= state->codes + ENOUGH - 1) {
copy->lencode = copy->codes + (state->lencode - state->codes); copy->lencode = copy->codes + (state->lencode - state->codes);
@ -1482,31 +1480,47 @@ z_streamp source;
return Z_OK; return Z_OK;
} }
int ZEXPORT inflateUndermine(strm, subvert) int ZEXPORT inflateUndermine(z_streamp strm, int subvert) {
z_streamp strm;
int subvert;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
state->sane = !subvert;
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
state->sane = !subvert;
return Z_OK; return Z_OK;
#else #else
(void)subvert;
state->sane = 1; state->sane = 1;
return Z_DATA_ERROR; return Z_DATA_ERROR;
#endif #endif
} }
long ZEXPORT inflateMark(strm) int ZEXPORT inflateValidate(z_streamp strm, int check) {
z_streamp strm;
{
struct inflate_state FAR *state; struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
return ((long)(state->back) << 16) + if (check && state->wrap)
state->wrap |= 4;
else
state->wrap &= ~4;
return Z_OK;
}
long ZEXPORT inflateMark(z_streamp strm) {
struct inflate_state FAR *state;
if (inflateStateCheck(strm))
return -(1L << 16);
state = (struct inflate_state FAR *)strm->state;
return (long)(((unsigned long)((long)state->back)) << 16) +
(state->mode == COPY ? state->length : (state->mode == COPY ? state->length :
(state->mode == MATCH ? state->was - state->length : 0)); (state->mode == MATCH ? state->was - state->length : 0));
} }
unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) {
struct inflate_state FAR *state;
if (inflateStateCheck(strm)) return (unsigned long)-1;
state = (struct inflate_state FAR *)strm->state;
return (unsigned long)(state->next - state->codes);
}

View file

@ -1,5 +1,5 @@
/* inflate.h -- internal inflate state definition /* inflate.h -- internal inflate state definition
* Copyright (C) 1995-2009 Mark Adler * Copyright (C) 1995-2019 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -18,7 +18,7 @@
/* Possible inflate modes between inflate() calls */ /* Possible inflate modes between inflate() calls */
typedef enum { typedef enum {
HEAD, /* i: waiting for magic header */ HEAD = 16180, /* i: waiting for magic header */
FLAGS, /* i: waiting for method and flags (gzip) */ FLAGS, /* i: waiting for method and flags (gzip) */
TIME, /* i: waiting for modification time (gzip) */ TIME, /* i: waiting for modification time (gzip) */
OS, /* i: waiting for extra flags and operating system (gzip) */ OS, /* i: waiting for extra flags and operating system (gzip) */
@ -77,13 +77,17 @@ typedef enum {
CHECK -> LENGTH -> DONE CHECK -> LENGTH -> DONE
*/ */
/* state maintained between inflate() calls. Approximately 10K bytes. */ /* State maintained between inflate() calls -- approximately 7K bytes, not
including the allocated sliding window, which is up to 32K bytes. */
struct inflate_state { struct inflate_state {
z_streamp strm; /* pointer back to this zlib stream */
inflate_mode mode; /* current inflate mode */ inflate_mode mode; /* current inflate mode */
int last; /* true if processing last block */ int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
bit 2 true to validate check value */
int havedict; /* true if dictionary provided */ int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */ int flags; /* gzip header method and flags, 0 if zlib, or
-1 if raw or no header yet */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
unsigned long check; /* protected copy of check value */ unsigned long check; /* protected copy of check value */
unsigned long total; /* protected copy of output count */ unsigned long total; /* protected copy of output count */

View file

@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2013 Mark Adler * Copyright (C) 1995-2024 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -9,7 +9,7 @@
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.8 Copyright 1995-2013 Mark Adler "; " inflate 1.3.1 Copyright 1995-2024 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@ -29,14 +29,9 @@ const char inflate_copyright[] =
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
codetype type; unsigned codes, code FAR * FAR *table,
unsigned short FAR *lens; unsigned FAR *bits, unsigned short FAR *work) {
unsigned codes;
code FAR * FAR *table;
unsigned FAR *bits;
unsigned short FAR *work;
{
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
@ -54,7 +49,7 @@ unsigned short FAR *work;
code FAR *next; /* next available space in table */ code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */ const unsigned short FAR *base; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */ const unsigned short FAR *extra; /* extra bits table to use */
int end; /* use base and extra for symbol > end */ unsigned match; /* use base and extra for symbol >= match */
unsigned short count[MAXBITS+1]; /* number of codes of each length */ unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
@ -62,7 +57,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@ -181,19 +176,17 @@ unsigned short FAR *work;
switch (type) { switch (type) {
case CODES: case CODES:
base = extra = work; /* dummy value--not used */ base = extra = work; /* dummy value--not used */
end = 19; match = 20;
break; break;
case LENS: case LENS:
base = lbase; base = lbase;
base -= 257;
extra = lext; extra = lext;
extra -= 257; match = 257;
end = 256;
break; break;
default: /* DISTS */ default: /* DISTS */
base = dbase; base = dbase;
extra = dext; extra = dext;
end = -1; match = 0;
} }
/* initialize state for loop */ /* initialize state for loop */
@ -216,13 +209,13 @@ unsigned short FAR *work;
for (;;) { for (;;) {
/* create table entry */ /* create table entry */
here.bits = (unsigned char)(len - drop); here.bits = (unsigned char)(len - drop);
if ((int)(work[sym]) < end) { if (work[sym] + 1U < match) {
here.op = (unsigned char)0; here.op = (unsigned char)0;
here.val = work[sym]; here.val = work[sym];
} }
else if ((int)(work[sym]) > end) { else if (work[sym] >= match) {
here.op = (unsigned char)(extra[work[sym]]); here.op = (unsigned char)(extra[work[sym] - match]);
here.val = base[work[sym]]; here.val = base[work[sym] - match];
} }
else { else {
here.op = (unsigned char)(32 + 64); /* end of block */ here.op = (unsigned char)(32 + 64); /* end of block */

View file

@ -38,11 +38,11 @@ typedef struct {
/* Maximum size of the dynamic table. The maximum number of code structures is /* Maximum size of the dynamic table. The maximum number of code structures is
1444, which is the sum of 852 for literal/length codes and 592 for distance 1444, which is the sum of 852 for literal/length codes and 592 for distance
codes. These values were found by exhaustive searches using the program codes. These values were found by exhaustive searches using the program
examples/enough.c found in the zlib distribtution. The arguments to that examples/enough.c found in the zlib distribution. The arguments to that
program are the number of symbols, the initial root table size, and the program are the number of symbols, the initial root table size, and the
maximum bit length of a code. "enough 286 9 15" for literal/length codes maximum bit length of a code. "enough 286 9 15" for literal/length codes
returns returns 852, and "enough 30 6 15" for distance codes returns 592. returns 852, and "enough 30 6 15" for distance codes returns 592. The
The initial root table size (9 or 6) is found in the fifth argument of the initial root table size (9 or 6) is found in the fifth argument of the
inflate_table() calls in inflate.c and infback.c. If the root table size is inflate_table() calls in inflate.c and infback.c. If the root table size is
changed, then these maximum sizes would be need to be recalculated and changed, then these maximum sizes would be need to be recalculated and
updated. */ updated. */
@ -57,6 +57,6 @@ typedef enum {
DISTS DISTS
} codetype; } codetype;
int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
unsigned codes, code FAR * FAR *table, unsigned codes, code FAR * FAR *table,
unsigned FAR *bits, unsigned short FAR *work)); unsigned FAR *bits, unsigned short FAR *work);

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/* uncompr.c -- decompress a memory buffer /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003, 2010 Jean-loup Gailly. * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -9,51 +9,77 @@
#include "zlib.h" #include "zlib.h"
/* =========================================================================== /* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is Decompresses the source buffer into the destination buffer. *sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total the byte length of the source buffer. Upon entry, *destLen is the total size
size of the destination buffer, which must be large enough to hold the of the destination buffer, which must be large enough to hold the entire
entire uncompressed data. (The size of the uncompressed data must have uncompressed data. (The size of the uncompressed data must have been saved
been saved previously by the compressor and transmitted to the decompressor previously by the compressor and transmitted to the decompressor by some
by some mechanism outside the scope of this compression library.) mechanism outside the scope of this compression library.) Upon exit,
Upon exit, destLen is the actual size of the compressed buffer. *destLen is the size of the decompressed data and *sourceLen is the number
of source bytes consumed. Upon return, source + *sourceLen points to the
first unused input byte.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
enough memory, Z_BUF_ERROR if there was not enough room in the output memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
buffer, or Z_DATA_ERROR if the input data was corrupted. Z_DATA_ERROR if the input data was corrupted, including if the input data is
an incomplete zlib stream.
*/ */
int ZEXPORT uncompress (dest, destLen, source, sourceLen) int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
Bytef *dest; uLong *sourceLen) {
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
z_stream stream; z_stream stream;
int err; int err;
const uInt max = (uInt)-1;
uLong len, left;
Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
len = *sourceLen;
if (*destLen) {
left = *destLen;
*destLen = 0;
}
else {
left = 1;
dest = buf;
}
stream.next_in = (z_const Bytef *)source; stream.next_in = (z_const Bytef *)source;
stream.avail_in = (uInt)sourceLen; stream.avail_in = 0;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0; stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0; stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = inflateInit(&stream); err = inflateInit(&stream);
if (err != Z_OK) return err; if (err != Z_OK) return err;
err = inflate(&stream, Z_FINISH); stream.next_out = dest;
if (err != Z_STREAM_END) { stream.avail_out = 0;
inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
*destLen = stream.total_out;
err = inflateEnd(&stream); do {
return err; if (stream.avail_out == 0) {
stream.avail_out = left > (uLong)max ? max : (uInt)left;
left -= stream.avail_out;
}
if (stream.avail_in == 0) {
stream.avail_in = len > (uLong)max ? max : (uInt)len;
len -= stream.avail_in;
}
err = inflate(&stream, Z_NO_FLUSH);
} while (err == Z_OK);
*sourceLen -= len + stream.avail_in;
if (dest != buf)
*destLen = stream.total_out;
else if (stream.total_out && err == Z_BUF_ERROR)
left = 1;
inflateEnd(&stream);
return err == Z_STREAM_END ? Z_OK :
err == Z_NEED_DICT ? Z_DATA_ERROR :
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
err;
}
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen) {
return uncompress2(dest, destLen, source, &sourceLen);
} }

View file

@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library /* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2013 Jean-loup Gailly. * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -17,7 +17,7 @@
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
# define Z_PREFIX_SET # define Z_PREFIX_SET
/* all linked symbols */ /* all linked symbols and init macros */
# define _dist_code z__dist_code # define _dist_code z__dist_code
# define _length_code z__length_code # define _length_code z__length_code
# define _tr_align z__tr_align # define _tr_align z__tr_align
@ -29,6 +29,7 @@
# define adler32 z_adler32 # define adler32 z_adler32
# define adler32_combine z_adler32_combine # define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64 # define adler32_combine64 z_adler32_combine64
# define adler32_z z_adler32_z
# ifndef Z_SOLO # ifndef Z_SOLO
# define compress z_compress # define compress z_compress
# define compress2 z_compress2 # define compress2 z_compress2
@ -37,10 +38,17 @@
# define crc32 z_crc32 # define crc32 z_crc32
# define crc32_combine z_crc32_combine # define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64 # define crc32_combine64 z_crc32_combine64
# define crc32_combine_gen z_crc32_combine_gen
# define crc32_combine_gen64 z_crc32_combine_gen64
# define crc32_combine_op z_crc32_combine_op
# define crc32_z z_crc32_z
# define deflate z_deflate # define deflate z_deflate
# define deflateBound z_deflateBound # define deflateBound z_deflateBound
# define deflateCopy z_deflateCopy # define deflateCopy z_deflateCopy
# define deflateEnd z_deflateEnd # define deflateEnd z_deflateEnd
# define deflateGetDictionary z_deflateGetDictionary
# define deflateInit z_deflateInit
# define deflateInit2 z_deflateInit2
# define deflateInit2_ z_deflateInit2_ # define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_ # define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams # define deflateParams z_deflateParams
@ -67,6 +75,8 @@
# define gzeof z_gzeof # define gzeof z_gzeof
# define gzerror z_gzerror # define gzerror z_gzerror
# define gzflush z_gzflush # define gzflush z_gzflush
# define gzfread z_gzfread
# define gzfwrite z_gzfwrite
# define gzgetc z_gzgetc # define gzgetc z_gzgetc
# define gzgetc_ z_gzgetc_ # define gzgetc_ z_gzgetc_
# define gzgets z_gzgets # define gzgets z_gzgets
@ -78,7 +88,6 @@
# define gzopen_w z_gzopen_w # define gzopen_w z_gzopen_w
# endif # endif
# define gzprintf z_gzprintf # define gzprintf z_gzprintf
# define gzvprintf z_gzvprintf
# define gzputc z_gzputc # define gzputc z_gzputc
# define gzputs z_gzputs # define gzputs z_gzputs
# define gzread z_gzread # define gzread z_gzread
@ -89,32 +98,39 @@
# define gztell z_gztell # define gztell z_gztell
# define gztell64 z_gztell64 # define gztell64 z_gztell64
# define gzungetc z_gzungetc # define gzungetc z_gzungetc
# define gzvprintf z_gzvprintf
# define gzwrite z_gzwrite # define gzwrite z_gzwrite
# endif # endif
# define inflate z_inflate # define inflate z_inflate
# define inflateBack z_inflateBack # define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd # define inflateBackEnd z_inflateBackEnd
# define inflateBackInit z_inflateBackInit
# define inflateBackInit_ z_inflateBackInit_ # define inflateBackInit_ z_inflateBackInit_
# define inflateCodesUsed z_inflateCodesUsed
# define inflateCopy z_inflateCopy # define inflateCopy z_inflateCopy
# define inflateEnd z_inflateEnd # define inflateEnd z_inflateEnd
# define inflateGetDictionary z_inflateGetDictionary
# define inflateGetHeader z_inflateGetHeader # define inflateGetHeader z_inflateGetHeader
# define inflateInit z_inflateInit
# define inflateInit2 z_inflateInit2
# define inflateInit2_ z_inflateInit2_ # define inflateInit2_ z_inflateInit2_
# define inflateInit_ z_inflateInit_ # define inflateInit_ z_inflateInit_
# define inflateMark z_inflateMark # define inflateMark z_inflateMark
# define inflatePrime z_inflatePrime # define inflatePrime z_inflatePrime
# define inflateReset z_inflateReset # define inflateReset z_inflateReset
# define inflateReset2 z_inflateReset2 # define inflateReset2 z_inflateReset2
# define inflateResetKeep z_inflateResetKeep
# define inflateSetDictionary z_inflateSetDictionary # define inflateSetDictionary z_inflateSetDictionary
# define inflateGetDictionary z_inflateGetDictionary
# define inflateSync z_inflateSync # define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint # define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine # define inflateUndermine z_inflateUndermine
# define inflateResetKeep z_inflateResetKeep # define inflateValidate z_inflateValidate
# define inflate_copyright z_inflate_copyright # define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast # define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table # define inflate_table z_inflate_table
# ifndef Z_SOLO # ifndef Z_SOLO
# define uncompress z_uncompress # define uncompress z_uncompress
# define uncompress2 z_uncompress2
# endif # endif
# define zError z_zError # define zError z_zError
# ifndef Z_SOLO # ifndef Z_SOLO
@ -224,9 +240,23 @@
# define z_const # define z_const
#endif #endif
/* Some Mac compilers merge all .h files incorrectly: */ #ifdef Z_SOLO
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) # ifdef _WIN64
# define NO_DUMMY_DECL typedef unsigned long long z_size_t;
# else
typedef unsigned long z_size_t;
# endif
#else
# define z_longlong long long
# if defined(NO_SIZE_T)
typedef unsigned NO_SIZE_T z_size_t;
# elif defined(STDC)
# include <stddef.h>
typedef size_t z_size_t;
# else
typedef unsigned long z_size_t;
# endif
# undef z_longlong
#endif #endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
@ -256,7 +286,7 @@
Of course this will generally degrade compression (there's no free lunch). Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
for small objects. for small objects.
*/ */
@ -270,14 +300,6 @@
# endif # endif
#endif #endif
#ifndef Z_ARG /* function prototypes for stdarg */
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
# define Z_ARG(args) args
# else
# define Z_ARG(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed /* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations). * model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have * This was tested only with MSC; for other MSDOS compilers you may have
@ -326,6 +348,9 @@
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
@ -444,11 +469,18 @@ typedef uLong FAR uLongf;
# undef _LARGEFILE64_SOURCE # undef _LARGEFILE64_SOURCE
#endif #endif
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) #ifndef Z_HAVE_UNISTD_H
# define Z_HAVE_UNISTD_H # ifdef __WATCOMC__
# define Z_HAVE_UNISTD_H
# endif
#endif
#ifndef Z_HAVE_UNISTD_H
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
# define Z_HAVE_UNISTD_H
# endif
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) # if defined(Z_HAVE_UNISTD_H)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# ifdef VMS # ifdef VMS
# include <unixio.h> /* for off_t */ # include <unixio.h> /* for off_t */
@ -484,7 +516,7 @@ typedef uLong FAR uLongf;
#if !defined(_WIN32) && defined(Z_LARGE64) #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#else #else
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) # if defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64 # define z_off64_t __int64
# else # else
# define z_off64_t z_off_t # define z_off64_t z_off_t

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/* zutil.c -- target dependent utility functions for the compression library /* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. * Copyright (C) 1995-2017 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -10,30 +10,25 @@
# include "gzguts.h" # include "gzguts.h"
#endif #endif
#ifndef NO_DUMMY_DECL
struct internal_state {int dummy;}; /* for buggy compilers */
#endif
z_const char * const z_errmsg[10] = { z_const char * const z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */ (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */ (z_const char *)"stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */ (z_const char *)"", /* Z_OK 0 */
"file error", /* Z_ERRNO (-1) */ (z_const char *)"file error", /* Z_ERRNO (-1) */
"stream error", /* Z_STREAM_ERROR (-2) */ (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
"data error", /* Z_DATA_ERROR (-3) */ (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
"insufficient memory", /* Z_MEM_ERROR (-4) */ (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
"buffer error", /* Z_BUF_ERROR (-5) */ (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
"incompatible version",/* Z_VERSION_ERROR (-6) */ (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
""}; (z_const char *)""
};
const char * ZEXPORT zlibVersion() const char * ZEXPORT zlibVersion(void) {
{
return ZLIB_VERSION; return ZLIB_VERSION;
} }
uLong ZEXPORT zlibCompileFlags() uLong ZEXPORT zlibCompileFlags(void) {
{
uLong flags; uLong flags;
flags = 0; flags = 0;
@ -61,12 +56,14 @@ uLong ZEXPORT zlibCompileFlags()
case 8: flags += 2 << 6; break; case 8: flags += 2 << 6; break;
default: flags += 3 << 6; default: flags += 3 << 6;
} }
#ifdef DEBUG #ifdef ZLIB_DEBUG
flags += 1 << 8; flags += 1 << 8;
#endif #endif
/*
#if defined(ASMV) || defined(ASMINF) #if defined(ASMV) || defined(ASMINF)
flags += 1 << 9; flags += 1 << 9;
#endif #endif
*/
#ifdef ZLIB_WINAPI #ifdef ZLIB_WINAPI
flags += 1 << 10; flags += 1 << 10;
#endif #endif
@ -115,16 +112,14 @@ uLong ZEXPORT zlibCompileFlags()
return flags; return flags;
} }
#ifdef DEBUG #ifdef ZLIB_DEBUG
#include <stdlib.h>
# ifndef verbose # ifndef verbose
# define verbose 0 # define verbose 0
# endif # endif
int ZLIB_INTERNAL z_verbose = verbose; int ZLIB_INTERNAL z_verbose = verbose;
void ZLIB_INTERNAL z_error (m) void ZLIB_INTERNAL z_error(char *m) {
char *m;
{
fprintf(stderr, "%s\n", m); fprintf(stderr, "%s\n", m);
exit(1); exit(1);
} }
@ -133,14 +128,12 @@ void ZLIB_INTERNAL z_error (m)
/* exported to allow conversion of error code to string for compress() and /* exported to allow conversion of error code to string for compress() and
* uncompress() * uncompress()
*/ */
const char * ZEXPORT zError(err) const char * ZEXPORT zError(int err) {
int err;
{
return ERR_MSG(err); return ERR_MSG(err);
} }
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
/* The Microsoft C Run-Time Library for Windows CE doesn't have /* The older Microsoft C Run-Time Library for Windows CE doesn't have
* errno. We define it as a global variable to simplify porting. * errno. We define it as a global variable to simplify porting.
* Its value is always 0 and should not be used. * Its value is always 0 and should not be used.
*/ */
@ -149,22 +142,14 @@ const char * ZEXPORT zError(err)
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
void ZLIB_INTERNAL zmemcpy(dest, source, len) void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
Bytef* dest;
const Bytef* source;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = *source++; /* ??? to be unrolled */ *dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0); } while (--len != 0);
} }
int ZLIB_INTERNAL zmemcmp(s1, s2, len) int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j; uInt j;
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
@ -173,10 +158,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len)
return 0; return 0;
} }
void ZLIB_INTERNAL zmemzero(dest, len) void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
Bytef* dest;
uInt len;
{
if (len == 0) return; if (len == 0) return;
do { do {
*dest++ = 0; /* ??? to be unrolled */ *dest++ = 0; /* ??? to be unrolled */
@ -217,11 +199,12 @@ local ptr_table table[MAX_PTR];
* a protected system like OS/2. Use Microsoft C instead. * a protected system like OS/2. Use Microsoft C instead.
*/ */
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
{ voidpf buf;
voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size; ulg bsize = (ulg)items*size;
(void)opaque;
/* If we allocate less than 65520 bytes, we assume that farmalloc /* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized. * will return a usable pointer which doesn't have to be normalized.
*/ */
@ -241,9 +224,11 @@ voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
return buf; return buf;
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{
int n; int n;
(void)opaque;
if (*(ush*)&ptr != 0) { /* object < 64K */ if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr); farfree(ptr);
return; return;
@ -259,7 +244,6 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
next_ptr--; next_ptr--;
return; return;
} }
ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found"); Assert(0, "zcfree: ptr not found");
} }
@ -276,15 +260,13 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
# define _hfree hfree # define _hfree hfree
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
{ (void)opaque;
if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size); return _halloc((long)items, size);
} }
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
{ (void)opaque;
if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr); _hfree(ptr);
} }
@ -296,27 +278,20 @@ void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
#ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC #ifndef STDC
extern voidp malloc OF((uInt size)); extern voidp malloc(uInt size);
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc(uInt items, uInt size);
extern void free OF((voidpf ptr)); extern void free(voidpf ptr);
#endif #endif
voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
voidpf opaque; (void)opaque;
unsigned items;
unsigned size;
{
if (opaque) items += size - size; /* make compiler happy */
return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
(voidpf)calloc(items, size); (voidpf)calloc(items, size);
} }
void ZLIB_INTERNAL zcfree (opaque, ptr) void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
voidpf opaque; (void)opaque;
voidpf ptr;
{
free(ptr); free(ptr);
if (opaque) return; /* make compiler happy */
} }
#endif /* MY_ZCALLOC */ #endif /* MY_ZCALLOC */

View file

@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library /* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2013 Jean-loup Gailly. * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -29,14 +29,12 @@
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef Z_SOLO
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
#endif
#ifndef local #ifndef local
# define local static # define local static
#endif #endif
/* compile with -Dlocal if your debugger can't find static symbols */ /* since "static" is used to mean two completely different things in C, we
define "local" for the non-static meaning of "static", for readability
(compile with -Dlocal if your debugger can't find static symbols) */
typedef unsigned char uch; typedef unsigned char uch;
typedef uch FAR uchf; typedef uch FAR uchf;
@ -44,10 +42,21 @@ typedef unsigned short ush;
typedef ush FAR ushf; typedef ush FAR ushf;
typedef unsigned long ulg; typedef unsigned long ulg;
#if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
# include <limits.h>
# if (ULONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long
# elif (ULLONG_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned long long
# elif (UINT_MAX == 0xffffffffffffffff)
# define Z_U8 unsigned
# endif
#endif
extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */ /* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)]
#define ERR_RETURN(strm,err) \ #define ERR_RETURN(strm,err) \
return (strm->msg = ERR_MSG(err), (err)) return (strm->msg = ERR_MSG(err), (err))
@ -98,67 +107,58 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif #endif
#ifdef AMIGA #ifdef AMIGA
# define OS_CODE 0x01 # define OS_CODE 1
#endif #endif
#if defined(VAXC) || defined(VMS) #if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02 # define OS_CODE 2
# define F_OPEN(name, mode) \ # define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif #endif
#ifdef __370__
# if __TARGET_LIB__ < 0x20000000
# define OS_CODE 4
# elif __TARGET_LIB__ < 0x40000000
# define OS_CODE 11
# else
# define OS_CODE 8
# endif
#endif
#if defined(ATARI) || defined(atarist) #if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05 # define OS_CODE 5
#endif #endif
#ifdef OS2 #ifdef OS2
# define OS_CODE 0x06 # define OS_CODE 6
# if defined(M_I86) && !defined(Z_SOLO) # if defined(M_I86) && !defined(Z_SOLO)
# include <malloc.h> # include <malloc.h>
# endif # endif
#endif #endif
#if defined(MACOS) || defined(TARGET_OS_MAC) #if defined(MACOS)
# define OS_CODE 0x07 # define OS_CODE 7
# ifndef Z_SOLO
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# endif
# endif
# endif
#endif #endif
#ifdef TOPS20 #ifdef __acorn
# define OS_CODE 0x0a # define OS_CODE 13
#endif #endif
#ifdef WIN32 #if defined(WIN32) && !defined(__CYGWIN__)
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ # define OS_CODE 10
# define OS_CODE 0x0b
# endif
#endif #endif
#ifdef __50SERIES /* Prime/PRIMOS */ #ifdef _BEOS_
# define OS_CODE 0x0f # define OS_CODE 16
#endif #endif
#if defined(_BEOS_) || defined(RISCOS) #ifdef __TOS_OS400__
# define fdopen(fd,mode) NULL /* No fdopen() */ # define OS_CODE 18
#endif #endif
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX #ifdef __APPLE__
# if defined(_WIN32_WCE) # define OS_CODE 19
# define fdopen(fd,mode) NULL /* No fdopen() */
# ifndef _PTRDIFF_T_DEFINED
typedef int ptrdiff_t;
# define _PTRDIFF_T_DEFINED
# endif
# else
# define fdopen(fd,type) _fdopen(fd,type)
# endif
#endif #endif
#if defined(__BORLANDC__) && !defined(MSDOS) #if defined(__BORLANDC__) && !defined(MSDOS)
@ -170,14 +170,15 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* provide prototypes for these when building zlib without LFS */ /* provide prototypes for these when building zlib without LFS */
#if !defined(_WIN32) && \ #if !defined(_WIN32) && \
(!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t);
ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t);
#endif #endif
/* common defaults */ /* common defaults */
#ifndef OS_CODE #ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */ # define OS_CODE 3 /* assume Unix */
#endif #endif
#ifndef F_OPEN #ifndef F_OPEN
@ -210,16 +211,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define zmemzero(dest, len) memset(dest, 0, len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len);
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len);
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len);
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef ZLIB_DEBUG
# include <stdio.h> # include <stdio.h>
extern int ZLIB_INTERNAL z_verbose; extern int ZLIB_INTERNAL z_verbose;
extern void ZLIB_INTERNAL z_error OF((char *m)); extern void ZLIB_INTERNAL z_error(char *m);
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;}
@ -236,9 +237,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items,
unsigned size)); unsigned size);
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr);
#endif #endif
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \

View file

@ -201,7 +201,91 @@ DWORD IQNetPlayer::GetCurrentRtt() { return 0; }
bool IQNetPlayer::IsHost() { return m_isHostPlayer; } bool IQNetPlayer::IsHost() { return m_isHostPlayer; }
bool IQNetPlayer::IsGuest() { return false; } bool IQNetPlayer::IsGuest() { return false; }
bool IQNetPlayer::IsLocal() { return !m_isRemote; } bool IQNetPlayer::IsLocal() { return !m_isRemote; }
PlayerUID IQNetPlayer::GetXuid() { return (PlayerUID)(0xe000d45248242f2e + m_smallId); } static void Win64_BuildSplitName(int iPad, char *outName, int outSize);
PlayerUID IQNetPlayer::GetXuid()
{
#ifdef _WINDOWS64
if (!m_isRemote)
{
int idx = (int)(this - &IQNet::m_player[0]);
if (idx == 0)
{
extern char g_Win64Username[17];
return Win64_UsernameToXuid(g_Win64Username);
}
if (idx > 0 && idx < XUSER_MAX_COUNT)
{
char splitName[32];
Win64_BuildSplitName(idx, splitName, sizeof(splitName));
return Win64_UsernameToXuid(splitName);
}
}
#endif
return (PlayerUID)(0xe000d45248242f2e + m_smallId);
}
PlayerUID Win64_UsernameToXuid(const char* username)
{
uint64_t hash = 14695981039346656037ULL;
for (const char* p = username; *p; ++p)
{
hash ^= (uint64_t)(unsigned char)(*p);
hash *= 1099511628211ULL;
}
const uint64_t WIN64_XUID_BASE = 0xe000d45248242f2e;
if (hash >= WIN64_XUID_BASE && hash <= WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS)
hash = WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS + 1;
if (hash == 0)
hash = 1;
return (PlayerUID)hash;
}
PlayerUID Win64_UsernameToXuid(const wchar_t* username)
{
char narrow[64];
int i = 0;
for (; username[i] && i < 63; ++i)
narrow[i] = (char)(unsigned char)(username[i] & 0xFF);
narrow[i] = 0;
return Win64_UsernameToXuid(narrow);
}
static void Win64_BuildSplitName(int iPad, char *outName, int outSize)
{
extern char g_Win64Username[17];
char candidate[32];
sprintf_s(candidate, sizeof(candidate), "%s_%d", g_Win64Username, iPad);
for (DWORD i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++)
{
if (!IQNet::m_player[i].m_isRemote) continue;
if (IQNet::m_player[i].m_gamertag[0] == 0) continue;
char remoteName[64];
int j = 0;
for (; IQNet::m_player[i].m_gamertag[j] && j < 63; ++j)
remoteName[j] = (char)(unsigned char)(IQNet::m_player[i].m_gamertag[j] & 0xFF);
remoteName[j] = 0;
if (_stricmp(candidate, remoteName) == 0)
{
sprintf_s(candidate, sizeof(candidate), "%s_%d_L", g_Win64Username, iPad);
break;
}
}
strncpy_s(outName, outSize, candidate, _TRUNCATE);
}
static void Win64_BuildSplitNameW(int iPad, wchar_t *outName, int outSize)
{
char narrow[32];
Win64_BuildSplitName(iPad, narrow, sizeof(narrow));
for (int i = 0; i < outSize - 1 && narrow[i]; ++i)
{
outName[i] = (wchar_t)(unsigned char)narrow[i];
outName[i + 1] = 0;
}
}
LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; } LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; }
int IQNetPlayer::GetSessionIndex() { return m_smallId; } int IQNetPlayer::GetSessionIndex() { return m_smallId; }
bool IQNetPlayer::IsTalking() { return false; } bool IQNetPlayer::IsTalking() { return false; }
@ -234,15 +318,28 @@ void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost,
static bool Win64_IsActivePlayer(IQNetPlayer *p, DWORD index); static bool Win64_IsActivePlayer(IQNetPlayer *p, DWORD index);
HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex){ return S_OK; } HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex)
{
if (dwUserIndex >= MINECRAFT_NET_MAX_PLAYERS) return E_FAIL;
m_player[dwUserIndex].m_isRemote = false;
m_player[dwUserIndex].m_smallId = (BYTE)dwUserIndex;
if (dwUserIndex > 0)
{
wchar_t splitNameW[32];
Win64_BuildSplitNameW((int)dwUserIndex, splitNameW, 32);
wcscpy_s(m_player[dwUserIndex].m_gamertag, 32, splitNameW);
}
if (dwUserIndex >= (DWORD)s_playerCount)
s_playerCount = dwUserIndex + 1;
return S_OK;
}
IQNetPlayer *IQNet::GetHostPlayer() { return &m_player[0]; } IQNetPlayer *IQNet::GetHostPlayer() { return &m_player[0]; }
IQNetPlayer *IQNet::GetLocalPlayerByUserIndex(DWORD dwUserIndex) IQNetPlayer *IQNet::GetLocalPlayerByUserIndex(DWORD dwUserIndex)
{ {
if (s_isHosting) if (s_isHosting)
{ {
if (dwUserIndex < MINECRAFT_NET_MAX_PLAYERS && if (dwUserIndex < MINECRAFT_NET_MAX_PLAYERS &&
!m_player[dwUserIndex].m_isRemote && !m_player[dwUserIndex].m_isRemote)
Win64_IsActivePlayer(&m_player[dwUserIndex], dwUserIndex))
return &m_player[dwUserIndex]; return &m_player[dwUserIndex];
return NULL; return NULL;
} }
@ -489,7 +586,7 @@ DWORD XEnableGuestSignin(BOOL fEnable) { return 0; }
#ifdef _WINDOWS64 #ifdef _WINDOWS64
static void *profileData[4]; static void *profileData[4];
static int profileDataSizePerPlayer = 0; static int profileDataSizePerPlayer = 0;
static bool s_bProfileIsFullVersion; static bool s_bProfileIsFullVersion = true;
static bool s_profileLoadedFromDisk[4] = {false, false, false, false}; static bool s_profileLoadedFromDisk[4] = {false, false, false, false};
bool Win64_HasSavedProfile(int iPad) bool Win64_HasSavedProfile(int iPad)
@ -604,7 +701,7 @@ void C_4JProfile::SetTrialTextStringTable(CXuiStringTable *pStringTable,int i
void C_4JProfile::SetTrialAwardText(eAwardType AwardType,int iTitle,int iText) {} void C_4JProfile::SetTrialAwardText(eAwardType AwardType,int iTitle,int iText) {}
int C_4JProfile::GetLockedProfile() { return 0; } int C_4JProfile::GetLockedProfile() { return 0; }
void C_4JProfile::SetLockedProfile(int iProf) {} void C_4JProfile::SetLockedProfile(int iProf) {}
bool C_4JProfile::IsSignedIn(int iQuadrant) { return ( iQuadrant == 0); } bool C_4JProfile::IsSignedIn(int iQuadrant) { return (iQuadrant >= 0 && iQuadrant < XUSER_MAX_COUNT); }
bool C_4JProfile::IsSignedInLive(int iProf) { return true; } bool C_4JProfile::IsSignedInLive(int iProf) { return true; }
bool C_4JProfile::IsGuest(int iQuadrant) { return false; } bool C_4JProfile::IsGuest(int iQuadrant) { return false; }
UINT C_4JProfile::RequestSignInUI(bool bFromInvite,bool bLocalGame,bool bNoGuestsAllowed,bool bMultiplayerSignIn,bool bAddUser, int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant) { return 0; } UINT C_4JProfile::RequestSignInUI(bool bFromInvite,bool bLocalGame,bool bNoGuestsAllowed,bool bMultiplayerSignIn,bool bAddUser, int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant) { return 0; }
@ -615,15 +712,21 @@ bool C_4JProfile::QuerySigninStatus(void) { return true; }
void C_4JProfile::GetXUID(int iPad, PlayerUID *pXuid,bool bOnlineXuid) void C_4JProfile::GetXUID(int iPad, PlayerUID *pXuid,bool bOnlineXuid)
{ {
#ifdef _WINDOWS64 #ifdef _WINDOWS64
if (iPad != 0) if (iPad == 0)
{
extern char g_Win64Username[17];
*pXuid = Win64_UsernameToXuid(g_Win64Username);
}
else if (iPad > 0 && iPad < XUSER_MAX_COUNT)
{
char splitName[32];
Win64_BuildSplitName(iPad, splitName, sizeof(splitName));
*pXuid = Win64_UsernameToXuid(splitName);
}
else
{ {
*pXuid = INVALID_XUID; *pXuid = INVALID_XUID;
return;
} }
if (IQNet::s_isHosting)
*pXuid = 0xe000d45248242f2e;
else
*pXuid = 0xe000d45248242f2e + WinsockNetLayer::GetLocalSmallId();
#else #else
*pXuid = 0xe000d45248242f2e + iPad; *pXuid = 0xe000d45248242f2e + iPad;
#endif #endif
@ -654,8 +757,30 @@ char fakeGamerTag[32] = "PlayerName";
void SetFakeGamertag(char *name){ strcpy_s(fakeGamerTag, name); } void SetFakeGamertag(char *name){ strcpy_s(fakeGamerTag, name); }
char* C_4JProfile::GetGamertag(int iPad){ return fakeGamerTag; } char* C_4JProfile::GetGamertag(int iPad){ return fakeGamerTag; }
#else #else
char* C_4JProfile::GetGamertag(int iPad){ extern char g_Win64Username[17]; return g_Win64Username; } static char s_win64SplitNames[4][32];
wstring C_4JProfile::GetDisplayName(int iPad){ extern wchar_t g_Win64UsernameW[17]; return g_Win64UsernameW; } char* C_4JProfile::GetGamertag(int iPad)
{
extern char g_Win64Username[17];
if (iPad == 0) return g_Win64Username;
if (iPad > 0 && iPad < XUSER_MAX_COUNT)
{
Win64_BuildSplitName(iPad, s_win64SplitNames[iPad], sizeof(s_win64SplitNames[iPad]));
return s_win64SplitNames[iPad];
}
return g_Win64Username;
}
wstring C_4JProfile::GetDisplayName(int iPad)
{
extern wchar_t g_Win64UsernameW[17];
if (iPad == 0) return g_Win64UsernameW;
if (iPad > 0 && iPad < XUSER_MAX_COUNT)
{
wchar_t buf[32];
Win64_BuildSplitNameW(iPad, buf, 32);
return buf;
}
return g_Win64UsernameW;
}
#endif #endif
bool C_4JProfile::IsFullVersion() { return s_bProfileIsFullVersion; } bool C_4JProfile::IsFullVersion() { return s_bProfileIsFullVersion; }
void C_4JProfile::SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam) {} void C_4JProfile::SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam) {}

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="ContentPackage_NO_TU|Durango"> <ProjectConfiguration Include="ContentPackage_NO_TU|Durango">
@ -850,7 +850,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;NDEBUG;_XBOX;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;NDEBUG;_XBOX;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -899,7 +899,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;NDEBUG;_XBOX;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;NDEBUG;_XBOX;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1053,7 +1053,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata"</Command>
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>PS3\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>PS3\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1108,7 +1108,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata"</Command>
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>PS3\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>PS3\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1163,7 +1163,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata"</Command>
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>PSVita\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>PSVita\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1420,7 +1420,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU</Comman
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_LARGE_WORLDS;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>Windows64\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Windows64\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1472,7 +1472,7 @@ copy /Y "$(ProjectDir)Durango\Sound\Minecraft.msscmp" "$(OutDir)Durango\Sound\"<
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_LARGE_WORLDS;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>Windows64\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Windows64\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1513,7 +1513,7 @@ copy /Y "$(ProjectDir)Durango\Sound\Minecraft.msscmp" "$(OutDir)Durango\Sound\"<
<BufferSecurityCheck>true</BufferSecurityCheck> <BufferSecurityCheck>true</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;PROFILE;NDEBUG;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;PROFILE;NDEBUG;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>Durango\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Durango\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -1591,7 +1591,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU</Comman
<BufferSecurityCheck>true</BufferSecurityCheck> <BufferSecurityCheck>true</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;PROFILE;NDEBUG;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;PROFILE;NDEBUG;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>Durango\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Durango\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
@ -2046,7 +2046,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata"</Command>
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_RELEASE_FOR_ART;_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_RELEASE_FOR_ART;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
@ -2098,7 +2098,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata"</Command>
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_RELEASE_FOR_ART;_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_RELEASE_FOR_ART;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
@ -2668,7 +2668,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU</Comman
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<OptimizationLevel>Level2</OptimizationLevel> <OptimizationLevel>Level2</OptimizationLevel>
<AdditionalIncludeDirectories>Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>..\Minecraft.World\ORBIS_Release\Minecraft.World.a;Orbis\4JLibs\libs\4j_Render.a;Orbis\4JLibs\libs\4j_Input_r.a;Orbis\4JLibs\libs\4J_Storage_r.a;Orbis\4JLibs\libs\4J_Profile_r.a;Orbis\Iggy\lib\libiggy_orbis.a;Orbis\Miles\lib\mssorbis.a;Orbis\Miles\lib\binkaorbis.a;Common\Network\Sony\sceRemoteStorage\ps4\lib\sceRemoteStorage.a;-lSceGnmDriver_stub_weak;-lSceGnmx;-lSceGnm;-lSceGpuAddress;-lSceCes;-lSceVideoOut_stub_weak;-lScePad_stub_weak;-lScePngDec_stub_weak;-lScePngEnc_stub_weak;-lSceFios2_stub_weak;-lSceUlt_stub_weak;-lSceShaderBinary;-lSceUserService_stub_weak;-lSceSysmodule_stub_weak;-lSceImeDialog_stub_weak;-lScePosix_stub_weak;-lSceAudioOut_stub_weak;-lSceSaveData_stub_weak;-lSceRtc_stub_weak;-lSceSystemService_stub_weak;-lSceNetCtl_stub_weak;-lSceNpCommon_stub_weak;-lSceNpManager_stub_weak;-lSceNpToolkit_rtti;-lSceNpToolkitUtils_rtti;-lSceNpWebApi_stub_weak;-lSceNpAuth_stub_weak;-lSceNpTrophy_stub_weak;-lSceInvitationDialog_stub_weak;-lSceGameCustomDataDialog_stub_weak;-lSceNpCommerce_stub_weak;-lSceNet_stub_weak;-lSceHttp_stub_weak;-lSceSsl_stub_weak;-lSceNpMatching2_stub_weak;-lSceNpTus_stub_weak;-lSceNpUtility_stub_weak;-lSceNpScore_stub_weak;-lSceCommonDialog_stub_weak;-lSceNpSns_stub_weak;-lSceNpSnsFacebookDialog_stub_weak;-lSceRudp_stub_weak;-lSceAppContent_stub_weak;-lSceVoice_stub_weak;-lSceAudioIn_stub_weak;-lSceRemoteplay_stub_weak;-lSceSaveDataDialog_stub_weak;-lSceErrorDialog_stub_weak;-lSceMsgDialog_stub_weak;-lSceGameLiveStreaming_stub_weak;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>..\Minecraft.World\ORBIS_Release\Minecraft.World.a;Orbis\4JLibs\libs\4j_Render.a;Orbis\4JLibs\libs\4j_Input_r.a;Orbis\4JLibs\libs\4J_Storage_r.a;Orbis\4JLibs\libs\4J_Profile_r.a;Orbis\Iggy\lib\libiggy_orbis.a;Orbis\Miles\lib\mssorbis.a;Orbis\Miles\lib\binkaorbis.a;Common\Network\Sony\sceRemoteStorage\ps4\lib\sceRemoteStorage.a;-lSceGnmDriver_stub_weak;-lSceGnmx;-lSceGnm;-lSceGpuAddress;-lSceCes;-lSceVideoOut_stub_weak;-lScePad_stub_weak;-lScePngDec_stub_weak;-lScePngEnc_stub_weak;-lSceFios2_stub_weak;-lSceUlt_stub_weak;-lSceShaderBinary;-lSceUserService_stub_weak;-lSceSysmodule_stub_weak;-lSceImeDialog_stub_weak;-lScePosix_stub_weak;-lSceAudioOut_stub_weak;-lSceSaveData_stub_weak;-lSceRtc_stub_weak;-lSceSystemService_stub_weak;-lSceNetCtl_stub_weak;-lSceNpCommon_stub_weak;-lSceNpManager_stub_weak;-lSceNpToolkit_rtti;-lSceNpToolkitUtils_rtti;-lSceNpWebApi_stub_weak;-lSceNpAuth_stub_weak;-lSceNpTrophy_stub_weak;-lSceInvitationDialog_stub_weak;-lSceGameCustomDataDialog_stub_weak;-lSceNpCommerce_stub_weak;-lSceNet_stub_weak;-lSceHttp_stub_weak;-lSceSsl_stub_weak;-lSceNpMatching2_stub_weak;-lSceNpTus_stub_weak;-lSceNpUtility_stub_weak;-lSceNpScore_stub_weak;-lSceCommonDialog_stub_weak;-lSceNpSns_stub_weak;-lSceNpSnsFacebookDialog_stub_weak;-lSceRudp_stub_weak;-lSceAppContent_stub_weak;-lSceVoice_stub_weak;-lSceAudioIn_stub_weak;-lSceRemoteplay_stub_weak;-lSceSaveDataDialog_stub_weak;-lSceErrorDialog_stub_weak;-lSceMsgDialog_stub_weak;-lSceGameLiveStreaming_stub_weak;%(AdditionalDependencies)</AdditionalDependencies>
@ -2688,7 +2688,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU</Comman
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<OptimizationLevel>Level2</OptimizationLevel> <OptimizationLevel>Level2</OptimizationLevel>
<AdditionalIncludeDirectories>Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>..\Minecraft.World\ORBIS_Release\Minecraft.World.a;Orbis\4JLibs\libs\4j_Render.a;Orbis\4JLibs\libs\4j_Input_r.a;Orbis\4JLibs\libs\4J_Storage_r.a;Orbis\4JLibs\libs\4J_Profile_r.a;Orbis\Iggy\lib\libiggy_orbis.a;Orbis\Miles\lib\mssorbis.a;Orbis\Miles\lib\binkaorbis.a;Common\Network\Sony\sceRemoteStorage\ps4\lib\sceRemoteStorage.a;-lSceGnmDriver_stub_weak;-lSceGnmx;-lSceGnm;-lSceGpuAddress;-lSceCes;-lSceVideoOut_stub_weak;-lScePad_stub_weak;-lScePngDec_stub_weak;-lScePngEnc_stub_weak;-lSceFios2_stub_weak;-lSceUlt_stub_weak;-lSceShaderBinary;-lSceUserService_stub_weak;-lSceSysmodule_stub_weak;-lSceImeDialog_stub_weak;-lScePosix_stub_weak;-lSceAudioOut_stub_weak;-lSceSaveData_stub_weak;-lSceRtc_stub_weak;-lSceSystemService_stub_weak;-lSceNetCtl_stub_weak;-lSceNpCommon_stub_weak;-lSceNpManager_stub_weak;-lSceNpToolkit_rtti;-lSceNpToolkitUtils_rtti;-lSceNpWebApi_stub_weak;-lSceNpAuth_stub_weak;-lSceNpTrophy_stub_weak;-lSceInvitationDialog_stub_weak;-lSceGameCustomDataDialog_stub_weak;-lSceNpCommerce_stub_weak;-lSceNet_stub_weak;-lSceHttp_stub_weak;-lSceSsl_stub_weak;-lSceNpMatching2_stub_weak;-lSceNpTus_stub_weak;-lSceNpUtility_stub_weak;-lSceNpScore_stub_weak;-lSceCommonDialog_stub_weak;-lSceNpSns_stub_weak;-lSceNpSnsFacebookDialog_stub_weak;-lSceRudp_stub_weak;-lSceAppContent_stub_weak;-lSceVoice_stub_weak;-lSceAudioIn_stub_weak;-lSceRemoteplay_stub_weak;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>..\Minecraft.World\ORBIS_Release\Minecraft.World.a;Orbis\4JLibs\libs\4j_Render.a;Orbis\4JLibs\libs\4j_Input_r.a;Orbis\4JLibs\libs\4J_Storage_r.a;Orbis\4JLibs\libs\4J_Profile_r.a;Orbis\Iggy\lib\libiggy_orbis.a;Orbis\Miles\lib\mssorbis.a;Orbis\Miles\lib\binkaorbis.a;Common\Network\Sony\sceRemoteStorage\ps4\lib\sceRemoteStorage.a;-lSceGnmDriver_stub_weak;-lSceGnmx;-lSceGnm;-lSceGpuAddress;-lSceCes;-lSceVideoOut_stub_weak;-lScePad_stub_weak;-lScePngDec_stub_weak;-lScePngEnc_stub_weak;-lSceFios2_stub_weak;-lSceUlt_stub_weak;-lSceShaderBinary;-lSceUserService_stub_weak;-lSceSysmodule_stub_weak;-lSceImeDialog_stub_weak;-lScePosix_stub_weak;-lSceAudioOut_stub_weak;-lSceSaveData_stub_weak;-lSceRtc_stub_weak;-lSceSystemService_stub_weak;-lSceNetCtl_stub_weak;-lSceNpCommon_stub_weak;-lSceNpManager_stub_weak;-lSceNpToolkit_rtti;-lSceNpToolkitUtils_rtti;-lSceNpWebApi_stub_weak;-lSceNpAuth_stub_weak;-lSceNpTrophy_stub_weak;-lSceInvitationDialog_stub_weak;-lSceGameCustomDataDialog_stub_weak;-lSceNpCommerce_stub_weak;-lSceNet_stub_weak;-lSceHttp_stub_weak;-lSceSsl_stub_weak;-lSceNpMatching2_stub_weak;-lSceNpTus_stub_weak;-lSceNpUtility_stub_weak;-lSceNpScore_stub_weak;-lSceCommonDialog_stub_weak;-lSceNpSns_stub_weak;-lSceNpSnsFacebookDialog_stub_weak;-lSceRudp_stub_weak;-lSceAppContent_stub_weak;-lSceVoice_stub_weak;-lSceAudioIn_stub_weak;-lSceRemoteplay_stub_weak;%(AdditionalDependencies)</AdditionalDependencies>
@ -2751,7 +2751,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU</Comman
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<AdditionalIncludeDirectories>Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED;_ART_BUILD</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_ART_BUILD</PreprocessorDefinitions>
<Warnings>WarningsOff</Warnings> <Warnings>WarningsOff</Warnings>
<OptimizationLevel>Levels</OptimizationLevel> <OptimizationLevel>Levels</OptimizationLevel>
</ClCompile> </ClCompile>

View file

@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library /* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2013 Jean-loup Gailly. * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
@ -17,7 +17,7 @@
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
# define Z_PREFIX_SET # define Z_PREFIX_SET
/* all linked symbols */ /* all linked symbols and init macros */
# define _dist_code z__dist_code # define _dist_code z__dist_code
# define _length_code z__length_code # define _length_code z__length_code
# define _tr_align z__tr_align # define _tr_align z__tr_align
@ -29,6 +29,7 @@
# define adler32 z_adler32 # define adler32 z_adler32
# define adler32_combine z_adler32_combine # define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64 # define adler32_combine64 z_adler32_combine64
# define adler32_z z_adler32_z
# ifndef Z_SOLO # ifndef Z_SOLO
# define compress z_compress # define compress z_compress
# define compress2 z_compress2 # define compress2 z_compress2
@ -37,10 +38,17 @@
# define crc32 z_crc32 # define crc32 z_crc32
# define crc32_combine z_crc32_combine # define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64 # define crc32_combine64 z_crc32_combine64
# define crc32_combine_gen z_crc32_combine_gen
# define crc32_combine_gen64 z_crc32_combine_gen64
# define crc32_combine_op z_crc32_combine_op
# define crc32_z z_crc32_z
# define deflate z_deflate # define deflate z_deflate
# define deflateBound z_deflateBound # define deflateBound z_deflateBound
# define deflateCopy z_deflateCopy # define deflateCopy z_deflateCopy
# define deflateEnd z_deflateEnd # define deflateEnd z_deflateEnd
# define deflateGetDictionary z_deflateGetDictionary
# define deflateInit z_deflateInit
# define deflateInit2 z_deflateInit2
# define deflateInit2_ z_deflateInit2_ # define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_ # define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams # define deflateParams z_deflateParams
@ -67,6 +75,8 @@
# define gzeof z_gzeof # define gzeof z_gzeof
# define gzerror z_gzerror # define gzerror z_gzerror
# define gzflush z_gzflush # define gzflush z_gzflush
# define gzfread z_gzfread
# define gzfwrite z_gzfwrite
# define gzgetc z_gzgetc # define gzgetc z_gzgetc
# define gzgetc_ z_gzgetc_ # define gzgetc_ z_gzgetc_
# define gzgets z_gzgets # define gzgets z_gzgets
@ -78,7 +88,6 @@
# define gzopen_w z_gzopen_w # define gzopen_w z_gzopen_w
# endif # endif
# define gzprintf z_gzprintf # define gzprintf z_gzprintf
# define gzvprintf z_gzvprintf
# define gzputc z_gzputc # define gzputc z_gzputc
# define gzputs z_gzputs # define gzputs z_gzputs
# define gzread z_gzread # define gzread z_gzread
@ -89,32 +98,39 @@
# define gztell z_gztell # define gztell z_gztell
# define gztell64 z_gztell64 # define gztell64 z_gztell64
# define gzungetc z_gzungetc # define gzungetc z_gzungetc
# define gzvprintf z_gzvprintf
# define gzwrite z_gzwrite # define gzwrite z_gzwrite
# endif # endif
# define inflate z_inflate # define inflate z_inflate
# define inflateBack z_inflateBack # define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd # define inflateBackEnd z_inflateBackEnd
# define inflateBackInit z_inflateBackInit
# define inflateBackInit_ z_inflateBackInit_ # define inflateBackInit_ z_inflateBackInit_
# define inflateCodesUsed z_inflateCodesUsed
# define inflateCopy z_inflateCopy # define inflateCopy z_inflateCopy
# define inflateEnd z_inflateEnd # define inflateEnd z_inflateEnd
# define inflateGetDictionary z_inflateGetDictionary
# define inflateGetHeader z_inflateGetHeader # define inflateGetHeader z_inflateGetHeader
# define inflateInit z_inflateInit
# define inflateInit2 z_inflateInit2
# define inflateInit2_ z_inflateInit2_ # define inflateInit2_ z_inflateInit2_
# define inflateInit_ z_inflateInit_ # define inflateInit_ z_inflateInit_
# define inflateMark z_inflateMark # define inflateMark z_inflateMark
# define inflatePrime z_inflatePrime # define inflatePrime z_inflatePrime
# define inflateReset z_inflateReset # define inflateReset z_inflateReset
# define inflateReset2 z_inflateReset2 # define inflateReset2 z_inflateReset2
# define inflateResetKeep z_inflateResetKeep
# define inflateSetDictionary z_inflateSetDictionary # define inflateSetDictionary z_inflateSetDictionary
# define inflateGetDictionary z_inflateGetDictionary
# define inflateSync z_inflateSync # define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint # define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine # define inflateUndermine z_inflateUndermine
# define inflateResetKeep z_inflateResetKeep # define inflateValidate z_inflateValidate
# define inflate_copyright z_inflate_copyright # define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast # define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table # define inflate_table z_inflate_table
# ifndef Z_SOLO # ifndef Z_SOLO
# define uncompress z_uncompress # define uncompress z_uncompress
# define uncompress2 z_uncompress2
# endif # endif
# define zError z_zError # define zError z_zError
# ifndef Z_SOLO # ifndef Z_SOLO
@ -224,9 +240,23 @@
# define z_const # define z_const
#endif #endif
/* Some Mac compilers merge all .h files incorrectly: */ #ifdef Z_SOLO
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) # ifdef _WIN64
# define NO_DUMMY_DECL typedef unsigned long long z_size_t;
# else
typedef unsigned long z_size_t;
# endif
#else
# define z_longlong long long
# if defined(NO_SIZE_T)
typedef unsigned NO_SIZE_T z_size_t;
# elif defined(STDC)
# include <stddef.h>
typedef size_t z_size_t;
# else
typedef unsigned long z_size_t;
# endif
# undef z_longlong
#endif #endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
@ -256,7 +286,7 @@
Of course this will generally degrade compression (there's no free lunch). Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes that is, 32K for windowBits=15 (default value) plus about 7 kilobytes
for small objects. for small objects.
*/ */
@ -270,14 +300,6 @@
# endif # endif
#endif #endif
#ifndef Z_ARG /* function prototypes for stdarg */
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
# define Z_ARG(args) args
# else
# define Z_ARG(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed /* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations). * model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have * This was tested only with MSC; for other MSDOS compilers you may have
@ -326,6 +348,9 @@
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
@ -418,7 +443,7 @@ typedef uLong FAR uLongf;
#ifdef STDC #ifdef STDC
# ifndef Z_SOLO # ifndef Z_SOLO
//# include <sys/types.h> /* for off_t */ # include <sys/types.h> /* for off_t */
# endif # endif
#endif #endif
@ -444,11 +469,18 @@ typedef uLong FAR uLongf;
# undef _LARGEFILE64_SOURCE # undef _LARGEFILE64_SOURCE
#endif #endif
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) #ifndef Z_HAVE_UNISTD_H
# define Z_HAVE_UNISTD_H # ifdef __WATCOMC__
# define Z_HAVE_UNISTD_H
# endif
#endif
#ifndef Z_HAVE_UNISTD_H
# if defined(_LARGEFILE64_SOURCE) && !defined(_WIN32)
# define Z_HAVE_UNISTD_H
# endif
#endif #endif
#ifndef Z_SOLO #ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) # if defined(Z_HAVE_UNISTD_H)
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# ifdef VMS # ifdef VMS
# include <unixio.h> /* for off_t */ # include <unixio.h> /* for off_t */
@ -484,7 +516,7 @@ typedef uLong FAR uLongf;
#if !defined(_WIN32) && defined(Z_LARGE64) #if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t # define z_off64_t off64_t
#else #else
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) # if defined(_WIN32) && !defined(__GNUC__)
# define z_off64_t __int64 # define z_off64_t __int64
# else # else
# define z_off64_t z_off_t # define z_off64_t z_off_t

File diff suppressed because it is too large Load diff

View file

@ -499,9 +499,13 @@ void PlayerChunkMap::getChunkAndRemovePlayer(int x, int z, shared_ptr<ServerPlay
// 4J - added - actually create & add player to a playerchunk, if there is one queued for this player. // 4J - added - actually create & add player to a playerchunk, if there is one queued for this player.
void PlayerChunkMap::tickAddRequests(shared_ptr<ServerPlayer> player) void PlayerChunkMap::tickAddRequests(shared_ptr<ServerPlayer> player)
{ {
if( addRequests.size() ) #ifdef _WINDOWS64
const int maxPerTick = 10;
#else
const int maxPerTick = 1;
#endif
for (int _processed = 0; _processed < maxPerTick && addRequests.size(); _processed++)
{ {
// Find the nearest chunk request to the player
int px = (int)player->x; int px = (int)player->x;
int pz = (int)player->z; int pz = (int)player->z;
int minDistSq = -1; int minDistSq = -1;
@ -523,12 +527,14 @@ void PlayerChunkMap::tickAddRequests(shared_ptr<ServerPlayer> player)
} }
} }
// If we found one at all, then do this one
if( itNearest != addRequests.end() ) if( itNearest != addRequests.end() )
{ {
getChunk(itNearest->x, itNearest->z, true)->add(itNearest->player); getChunk(itNearest->x, itNearest->z, true)->add(itNearest->player);
addRequests.erase(itNearest); addRequests.erase(itNearest);
return; }
else
{
break;
} }
} }
} }

View file

@ -126,7 +126,7 @@ void PlayerConnection::disconnect(DisconnectPacket::eDisconnectReason reason)
send( shared_ptr<DisconnectPacket>( new DisconnectPacket(reason) )); send( shared_ptr<DisconnectPacket>( new DisconnectPacket(reason) ));
connection->sendAndQuit(); connection->sendAndQuit();
// 4J-PB - removed, since it needs to be localised in the language the client is in // 4J-PB - removed, since it needs to be localised in the language the client is in
//server->players->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(L"§e" + player->name + L" left the game.") ) ); //server->players->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(L"<EFBFBD>e" + player->name + L" left the game.") ) );
if(getWasKicked()) if(getWasKicked())
{ {
server->getPlayers()->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) ); server->getPlayers()->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) );
@ -569,7 +569,7 @@ void PlayerConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason,
if( done ) return; if( done ) return;
// logger.info(player.name + " lost connection: " + reason); // logger.info(player.name + " lost connection: " + reason);
// 4J-PB - removed, since it needs to be localised in the language the client is in // 4J-PB - removed, since it needs to be localised in the language the client is in
//server->players->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(L"§e" + player->name + L" left the game.") ) ); //server->players->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(L"<EFBFBD>e" + player->name + L" left the game.") ) );
if(getWasKicked()) if(getWasKicked())
{ {
server->getPlayers()->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) ); server->getPlayers()->broadcastAll( shared_ptr<ChatPacket>( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) );
@ -740,13 +740,13 @@ int PlayerConnection::countDelayedPackets()
void PlayerConnection::info(const wstring& string) void PlayerConnection::info(const wstring& string)
{ {
// 4J-PB - removed, since it needs to be localised in the language the client is in // 4J-PB - removed, since it needs to be localised in the language the client is in
//send( shared_ptr<ChatPacket>( new ChatPacket(L"§7" + string) ) ); //send( shared_ptr<ChatPacket>( new ChatPacket(L"<EFBFBD>7" + string) ) );
} }
void PlayerConnection::warn(const wstring& string) void PlayerConnection::warn(const wstring& string)
{ {
// 4J-PB - removed, since it needs to be localised in the language the client is in // 4J-PB - removed, since it needs to be localised in the language the client is in
//send( shared_ptr<ChatPacket>( new ChatPacket(L"§9" + string) ) ); //send( shared_ptr<ChatPacket>( new ChatPacket(L"<EFBFBD>9" + string) ) );
} }
wstring PlayerConnection::getConsoleName() wstring PlayerConnection::getConsoleName()
@ -1513,7 +1513,10 @@ void PlayerConnection::handleCustomPayload(shared_ptr<CustomPayloadPacket> custo
void PlayerConnection::handleDebugOptions(shared_ptr<DebugOptionsPacket> packet) void PlayerConnection::handleDebugOptions(shared_ptr<DebugOptionsPacket> packet)
{ {
//Player player = dynamic_pointer_cast<Player>( player->shared_from_this() ); //Player player = dynamic_pointer_cast<Player>( player->shared_from_this() );
player->SetDebugOptions(packet->m_uiVal); if(app.DebugSettingsOn())
{
player->SetDebugOptions(packet->m_uiVal);
}
} }
void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet) void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet)
@ -1523,6 +1526,10 @@ void PlayerConnection::handleCraftItem(shared_ptr<CraftItemPacket> packet)
if(iRecipe == -1) if(iRecipe == -1)
return; return;
int recipeCount = (int)Recipes::getInstance()->getRecipies()->size();
if(iRecipe < 0 || iRecipe >= recipeCount)
return;
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);

View file

@ -479,9 +479,12 @@ shared_ptr<ServerPlayer> PlayerList::getPlayerForLogin(PendingConnection *pendin
INetworkPlayer *np = pendingConnection->connection->getSocket()->getPlayer(); INetworkPlayer *np = pendingConnection->connection->getSocket()->getPlayer();
if (np != NULL) if (np != NULL)
{ {
PlayerUID realXuid = np->GetUID();
player->setXuid(realXuid); PlayerUID persistXuid = Win64_UsernameToXuid(userName.c_str());
player->setOnlineXuid(realXuid); player->setXuid(persistXuid);
// network player identification, not used for saves
PlayerUID networkXuid = np->GetUID();
player->setOnlineXuid(networkXuid);
} }
} }
#endif #endif

View file

@ -982,7 +982,9 @@ void ServerLevel::entityRemoved(shared_ptr<Entity> e)
shared_ptr<Entity> ServerLevel::getEntity(int id) shared_ptr<Entity> ServerLevel::getEntity(int id)
{ {
return entitiesById[id]; AUTO_VAR(it, entitiesById.find(id));
if(it != entitiesById.end()) return it->second;
return nullptr;
} }
bool ServerLevel::addGlobalEntity(shared_ptr<Entity> e) bool ServerLevel::addGlobalEntity(shared_ptr<Entity> e)

View file

@ -306,6 +306,10 @@ void ServerPlayer::doTickA()
// 4J - split off the chunk sending bit of the tick here from ::doTick so we can do this exactly once per player per server tick // 4J - split off the chunk sending bit of the tick here from ::doTick so we can do this exactly once per player per server tick
void ServerPlayer::doChunkSendingTick(bool dontDelayChunks) void ServerPlayer::doChunkSendingTick(bool dontDelayChunks)
{ {
#ifdef _WINDOWS64
for (int _w64cs = 0; _w64cs < 4; _w64cs++)
{
#endif
// printf("[%d] %s: sendChunks: %d, empty: %d\n",tickCount, connection->getNetworkPlayer()->GetUID().getOnlineID(),sendChunks,chunksToSend.empty()); // printf("[%d] %s: sendChunks: %d, empty: %d\n",tickCount, connection->getNetworkPlayer()->GetUID().getOnlineID(),sendChunks,chunksToSend.empty());
if (!chunksToSend.empty()) if (!chunksToSend.empty())
{ {
@ -344,6 +348,17 @@ void ServerPlayer::doChunkSendingTick(bool dontDelayChunks)
} }
else else
{ {
#ifdef _WINDOWS64
if( dontDelayChunks ||
((connection->countDelayedPackets() < 16 )&&
(g_NetworkManager.GetHostPlayer()->GetSendQueueSizeMessages( NULL, true ) < 16 )&&
!connection->done) )
{
lastBrupSendTickCount = tickCount;
okToSend = true;
MinecraftServer::s_slowQueuePacketSent = true;
}
#else
bool canSendOnSlowQueue = MinecraftServer::canSendOnSlowQueue(connection->getNetworkPlayer()); bool canSendOnSlowQueue = MinecraftServer::canSendOnSlowQueue(connection->getNetworkPlayer());
// app.DebugPrintf("%ls: canSendOnSlowQueue %d, countDelayedPackets %d GetSendQueueSizeBytes %d done: %d", // app.DebugPrintf("%ls: canSendOnSlowQueue %d, countDelayedPackets %d GetSendQueueSizeBytes %d done: %d",
@ -379,6 +394,7 @@ void ServerPlayer::doChunkSendingTick(bool dontDelayChunks)
{ {
// app.DebugPrintf(" - <NOT OK>\n"); // app.DebugPrintf(" - <NOT OK>\n");
} }
#endif
} }
if (okToSend) if (okToSend)
@ -445,7 +461,7 @@ void ServerPlayer::doChunkSendingTick(bool dontDelayChunks)
for (unsigned int i = 0; i < tes->size(); i++) for (unsigned int i = 0; i < tes->size(); i++)
{ {
// 4J Stu - Added delay param to ensure that these arrive after the BRUPs from above // 4J Stu - Added delay param to ensure that these arrive after the BRUPs from above
// Fix for #9169 - ART : Sign text is replaced with the words “Awaiting approval”. // Fix for #9169 - ART : Sign text is replaced with the words <EFBFBD>Awaiting approval<61>.
broadcast(tes->at(i), !connection->isLocal() && !dontDelayChunks); broadcast(tes->at(i), !connection->isLocal() && !dontDelayChunks);
} }
delete tes; delete tes;
@ -453,6 +469,9 @@ void ServerPlayer::doChunkSendingTick(bool dontDelayChunks)
} }
} }
} }
#ifdef _WINDOWS64
}
#endif
} }
void ServerPlayer::doTickB(bool ignorePortal) void ServerPlayer::doTickB(bool ignorePortal)

View file

@ -25,7 +25,7 @@ BYTE WinsockNetLayer::s_nextSmallId = 1;
CRITICAL_SECTION WinsockNetLayer::s_sendLock; CRITICAL_SECTION WinsockNetLayer::s_sendLock;
CRITICAL_SECTION WinsockNetLayer::s_connectionsLock; CRITICAL_SECTION WinsockNetLayer::s_connectionsLock;
std::vector<Win64RemoteConnection> WinsockNetLayer::s_connections; Win64RemoteConnection WinsockNetLayer::s_connections[WIN64_NET_MAX_CLIENTS + 1];
SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET; SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET;
HANDLE WinsockNetLayer::s_advertiseThread = NULL; HANDLE WinsockNetLayer::s_advertiseThread = NULL;
@ -43,6 +43,9 @@ std::vector<Win64LANSession> WinsockNetLayer::s_discoveredSessions;
CRITICAL_SECTION WinsockNetLayer::s_disconnectLock; CRITICAL_SECTION WinsockNetLayer::s_disconnectLock;
std::vector<BYTE> WinsockNetLayer::s_disconnectedSmallIds; std::vector<BYTE> WinsockNetLayer::s_disconnectedSmallIds;
CRITICAL_SECTION WinsockNetLayer::s_pendingJoinLock;
std::vector<BYTE> WinsockNetLayer::s_pendingJoinSmallIds;
CRITICAL_SECTION WinsockNetLayer::s_freeSmallIdLock; CRITICAL_SECTION WinsockNetLayer::s_freeSmallIdLock;
std::vector<BYTE> WinsockNetLayer::s_freeSmallIds; std::vector<BYTE> WinsockNetLayer::s_freeSmallIds;
@ -68,8 +71,18 @@ bool WinsockNetLayer::Initialize()
InitializeCriticalSection(&s_advertiseLock); InitializeCriticalSection(&s_advertiseLock);
InitializeCriticalSection(&s_discoveryLock); InitializeCriticalSection(&s_discoveryLock);
InitializeCriticalSection(&s_disconnectLock); InitializeCriticalSection(&s_disconnectLock);
InitializeCriticalSection(&s_pendingJoinLock);
InitializeCriticalSection(&s_freeSmallIdLock); InitializeCriticalSection(&s_freeSmallIdLock);
for (int i = 0; i < WIN64_NET_MAX_CLIENTS + 1; i++)
{
s_connections[i].tcpSocket = INVALID_SOCKET;
s_connections[i].smallId = 0;
s_connections[i].recvThread = NULL;
s_connections[i].active = false;
InitializeCriticalSection(&s_connections[i].sendLock);
}
s_initialized = true; s_initialized = true;
StartDiscovery(); StartDiscovery();
@ -98,15 +111,22 @@ void WinsockNetLayer::Shutdown()
} }
EnterCriticalSection(&s_connectionsLock); EnterCriticalSection(&s_connectionsLock);
for (size_t i = 0; i < s_connections.size(); i++) for (int i = 0; i < WIN64_NET_MAX_CLIENTS + 1; i++)
{ {
s_connections[i].active = false; s_connections[i].active = false;
if (s_connections[i].tcpSocket != INVALID_SOCKET) if (s_connections[i].tcpSocket != INVALID_SOCKET)
{ {
closesocket(s_connections[i].tcpSocket); closesocket(s_connections[i].tcpSocket);
s_connections[i].tcpSocket = INVALID_SOCKET;
} }
if (s_connections[i].recvThread != NULL)
{
WaitForSingleObject(s_connections[i].recvThread, 2000);
CloseHandle(s_connections[i].recvThread);
s_connections[i].recvThread = NULL;
}
DeleteCriticalSection(&s_connections[i].sendLock);
} }
s_connections.clear();
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
if (s_acceptThread != NULL) if (s_acceptThread != NULL)
@ -131,6 +151,8 @@ void WinsockNetLayer::Shutdown()
DeleteCriticalSection(&s_discoveryLock); DeleteCriticalSection(&s_discoveryLock);
DeleteCriticalSection(&s_disconnectLock); DeleteCriticalSection(&s_disconnectLock);
s_disconnectedSmallIds.clear(); s_disconnectedSmallIds.clear();
DeleteCriticalSection(&s_pendingJoinLock);
s_pendingJoinSmallIds.clear();
DeleteCriticalSection(&s_freeSmallIdLock); DeleteCriticalSection(&s_freeSmallIdLock);
s_freeSmallIds.clear(); s_freeSmallIds.clear();
WSACleanup(); WSACleanup();
@ -346,9 +368,7 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize) bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
{ {
if (sock == INVALID_SOCKET || dataSize <= 0) return false; if (sock == INVALID_SOCKET || dataSize <= 0 || dataSize > WIN64_NET_MAX_PACKET_SIZE) return false;
EnterCriticalSection(&s_sendLock);
BYTE header[4]; BYTE header[4];
header[0] = (BYTE)((dataSize >> 24) & 0xFF); header[0] = (BYTE)((dataSize >> 24) & 0xFF);
@ -362,10 +382,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
{ {
int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0); int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0);
if (sent == SOCKET_ERROR || sent == 0) if (sent == SOCKET_ERROR || sent == 0)
{
LeaveCriticalSection(&s_sendLock);
return false; return false;
}
totalSent += sent; totalSent += sent;
} }
@ -374,14 +391,10 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
{ {
int sent = send(sock, (const char *)data + totalSent, dataSize - totalSent, 0); int sent = send(sock, (const char *)data + totalSent, dataSize - totalSent, 0);
if (sent == SOCKET_ERROR || sent == 0) if (sent == SOCKET_ERROR || sent == 0)
{
LeaveCriticalSection(&s_sendLock);
return false; return false;
}
totalSent += sent; totalSent += sent;
} }
LeaveCriticalSection(&s_sendLock);
return true; return true;
} }
@ -391,27 +404,38 @@ bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void *data, int da
if (s_isHost) if (s_isHost)
{ {
SOCKET sock = GetSocketForSmallId(targetSmallId); EnterCriticalSection(&s_connectionsLock);
if (sock == INVALID_SOCKET) return false; if (targetSmallId >= WIN64_NET_MAX_CLIENTS + 1 || !s_connections[targetSmallId].active)
return SendOnSocket(sock, data, dataSize); {
LeaveCriticalSection(&s_connectionsLock);
return false;
}
SOCKET sock = s_connections[targetSmallId].tcpSocket;
CRITICAL_SECTION *pLock = &s_connections[targetSmallId].sendLock;
LeaveCriticalSection(&s_connectionsLock);
EnterCriticalSection(pLock);
bool result = SendOnSocket(sock, data, dataSize);
LeaveCriticalSection(pLock);
return result;
} }
else else
{ {
return SendOnSocket(s_hostConnectionSocket, data, dataSize); EnterCriticalSection(&s_sendLock);
bool result = SendOnSocket(s_hostConnectionSocket, data, dataSize);
LeaveCriticalSection(&s_sendLock);
return result;
} }
} }
SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId) SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId)
{ {
EnterCriticalSection(&s_connectionsLock); EnterCriticalSection(&s_connectionsLock);
for (size_t i = 0; i < s_connections.size(); i++) if (smallId < WIN64_NET_MAX_CLIENTS + 1 && s_connections[smallId].active)
{ {
if (s_connections[i].smallId == smallId && s_connections[i].active) SOCKET sock = s_connections[smallId].tcpSocket;
{ LeaveCriticalSection(&s_connectionsLock);
SOCKET sock = s_connections[i].tcpSocket; return sock;
LeaveCriticalSection(&s_connectionsLock);
return sock;
}
} }
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
return INVALID_SOCKET; return INVALID_SOCKET;
@ -502,15 +526,18 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
continue; continue;
} }
Win64RemoteConnection conn; Win64RemoteConnection &conn = s_connections[assignedSmallId];
EnterCriticalSection(&s_connectionsLock);
if (conn.recvThread != NULL)
{
WaitForSingleObject(conn.recvThread, 2000);
CloseHandle(conn.recvThread);
conn.recvThread = NULL;
}
conn.tcpSocket = clientSocket; conn.tcpSocket = clientSocket;
conn.smallId = assignedSmallId; conn.smallId = assignedSmallId;
conn.active = true; conn.active = true;
conn.recvThread = NULL;
EnterCriticalSection(&s_connectionsLock);
s_connections.push_back(conn);
int connIdx = (int)s_connections.size() - 1;
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
app.DebugPrintf("Win64 LAN: Client connected, assigned smallId=%d\n", assignedSmallId); app.DebugPrintf("Win64 LAN: Client connected, assigned smallId=%d\n", assignedSmallId);
@ -520,16 +547,17 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
extern void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal); extern void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal);
Win64_SetupRemoteQNetPlayer(qnetPlayer, assignedSmallId, false, false); Win64_SetupRemoteQNetPlayer(qnetPlayer, assignedSmallId, false, false);
extern CPlatformNetworkManagerStub *g_pPlatformNetworkManager;
g_pPlatformNetworkManager->NotifyPlayerJoined(qnetPlayer); EnterCriticalSection(&s_pendingJoinLock);
s_pendingJoinSmallIds.push_back(assignedSmallId);
LeaveCriticalSection(&s_pendingJoinLock);
DWORD *threadParam = new DWORD; DWORD *threadParam = new DWORD;
*threadParam = connIdx; *threadParam = assignedSmallId;
HANDLE hThread = CreateThread(NULL, 0, RecvThreadProc, threadParam, 0, NULL); HANDLE hThread = CreateThread(NULL, 0, RecvThreadProc, threadParam, 0, NULL);
EnterCriticalSection(&s_connectionsLock); EnterCriticalSection(&s_connectionsLock);
if (connIdx < (int)s_connections.size()) s_connections[assignedSmallId].recvThread = hThread;
s_connections[connIdx].recvThread = hThread;
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
} }
return 0; return 0;
@ -537,17 +565,16 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param) DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param)
{ {
DWORD connIdx = *(DWORD *)param; BYTE clientSmallId = (BYTE)*(DWORD *)param;
delete (DWORD *)param; delete (DWORD *)param;
EnterCriticalSection(&s_connectionsLock); EnterCriticalSection(&s_connectionsLock);
if (connIdx >= (DWORD)s_connections.size()) if (clientSmallId >= WIN64_NET_MAX_CLIENTS + 1 || !s_connections[clientSmallId].active)
{ {
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
return 0; return 0;
} }
SOCKET sock = s_connections[connIdx].tcpSocket; SOCKET sock = s_connections[clientSmallId].tcpSocket;
BYTE clientSmallId = s_connections[connIdx].smallId;
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
std::vector<BYTE> recvBuf; std::vector<BYTE> recvBuf;
@ -568,7 +595,7 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param)
((uint32_t)header[2] << 8) | ((uint32_t)header[2] << 8) |
((uint32_t)header[3]); ((uint32_t)header[3]);
if (packetSize <= 0 || packetSize > WIN64_NET_MAX_PACKET_SIZE) if (packetSize <= 0 || (unsigned int)packetSize > WIN64_NET_MAX_PACKET_SIZE)
{ {
app.DebugPrintf("Win64 LAN: Invalid packet size %d from client smallId=%d (max=%d)\n", app.DebugPrintf("Win64 LAN: Invalid packet size %d from client smallId=%d (max=%d)\n",
packetSize, packetSize,
@ -593,18 +620,11 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param)
} }
EnterCriticalSection(&s_connectionsLock); EnterCriticalSection(&s_connectionsLock);
for (size_t i = 0; i < s_connections.size(); i++) s_connections[clientSmallId].active = false;
if (s_connections[clientSmallId].tcpSocket != INVALID_SOCKET)
{ {
if (s_connections[i].smallId == clientSmallId) closesocket(s_connections[clientSmallId].tcpSocket);
{ s_connections[clientSmallId].tcpSocket = INVALID_SOCKET;
s_connections[i].active = false;
if (s_connections[i].tcpSocket != INVALID_SOCKET)
{
closesocket(s_connections[i].tcpSocket);
s_connections[i].tcpSocket = INVALID_SOCKET;
}
break;
}
} }
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
@ -636,18 +656,34 @@ void WinsockNetLayer::PushFreeSmallId(BYTE smallId)
LeaveCriticalSection(&s_freeSmallIdLock); LeaveCriticalSection(&s_freeSmallIdLock);
} }
bool WinsockNetLayer::PopPendingJoinSmallId(BYTE *outSmallId)
{
bool found = false;
EnterCriticalSection(&s_pendingJoinLock);
if (!s_pendingJoinSmallIds.empty())
{
*outSmallId = s_pendingJoinSmallIds.back();
s_pendingJoinSmallIds.pop_back();
found = true;
}
LeaveCriticalSection(&s_pendingJoinLock);
return found;
}
bool WinsockNetLayer::IsSmallIdConnected(BYTE smallId)
{
if (smallId >= WIN64_NET_MAX_CLIENTS + 1) return false;
return s_connections[smallId].active;
}
void WinsockNetLayer::CloseConnectionBySmallId(BYTE smallId) void WinsockNetLayer::CloseConnectionBySmallId(BYTE smallId)
{ {
EnterCriticalSection(&s_connectionsLock); EnterCriticalSection(&s_connectionsLock);
for (size_t i = 0; i < s_connections.size(); i++) if (smallId < WIN64_NET_MAX_CLIENTS + 1 && s_connections[smallId].active && s_connections[smallId].tcpSocket != INVALID_SOCKET)
{ {
if (s_connections[i].smallId == smallId && s_connections[i].active && s_connections[i].tcpSocket != INVALID_SOCKET) closesocket(s_connections[smallId].tcpSocket);
{ s_connections[smallId].tcpSocket = INVALID_SOCKET;
closesocket(s_connections[i].tcpSocket); app.DebugPrintf("Win64 LAN: Force-closed TCP connection for smallId=%d\n", smallId);
s_connections[i].tcpSocket = INVALID_SOCKET;
app.DebugPrintf("Win64 LAN: Force-closed TCP connection for smallId=%d\n", smallId);
break;
}
} }
LeaveCriticalSection(&s_connectionsLock); LeaveCriticalSection(&s_connectionsLock);
} }
@ -666,9 +702,9 @@ DWORD WINAPI WinsockNetLayer::ClientRecvThreadProc(LPVOID param)
break; break;
} }
int packetSize = (header[0] << 24) | (header[1] << 16) | (header[2] << 8) | header[3]; int packetSize = ((uint32_t)header[0] << 24) | ((uint32_t)header[1] << 16) | ((uint32_t)header[2] << 8) | (uint32_t)header[3];
if (packetSize <= 0 || packetSize > WIN64_NET_MAX_PACKET_SIZE) if (packetSize <= 0 || (unsigned int)packetSize > WIN64_NET_MAX_PACKET_SIZE)
{ {
app.DebugPrintf("Win64 LAN: Invalid packet size %d from host (max=%d)\n", app.DebugPrintf("Win64 LAN: Invalid packet size %d from host (max=%d)\n",
packetSize, packetSize,
@ -679,7 +715,6 @@ DWORD WINAPI WinsockNetLayer::ClientRecvThreadProc(LPVOID param)
if ((int)recvBuf.size() < packetSize) if ((int)recvBuf.size() < packetSize)
{ {
recvBuf.resize(packetSize); recvBuf.resize(packetSize);
app.DebugPrintf("Win64 LAN: Resized client recv buffer to %d bytes\n", packetSize);
} }
if (!RecvExact(s_hostConnectionSocket, &recvBuf[0], packetSize)) if (!RecvExact(s_hostConnectionSocket, &recvBuf[0], packetSize))
@ -877,6 +912,7 @@ std::vector<Win64LANSession> WinsockNetLayer::GetDiscoveredSessions()
DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param) DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
{ {
char recvBuf[1024]; char recvBuf[1024];
const size_t MAX_DISCOVERED_SESSIONS = 64;
while (s_discovering) while (s_discovering)
{ {
@ -898,6 +934,11 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
if (broadcast->magic != WIN64_LAN_BROADCAST_MAGIC) if (broadcast->magic != WIN64_LAN_BROADCAST_MAGIC)
continue; continue;
broadcast->hostName[31] = L'\0';
for (int pn = 0; pn < 8; pn++)
broadcast->playerNames[pn][XUSER_NAME_SIZE - 1] = '\0';
char senderIP[64]; char senderIP[64];
inet_ntop(AF_INET, &senderAddr.sin_addr, senderIP, sizeof(senderIP)); inet_ntop(AF_INET, &senderAddr.sin_addr, senderIP, sizeof(senderIP));
@ -928,6 +969,12 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
if (!found) if (!found)
{ {
if (s_discoveredSessions.size() >= MAX_DISCOVERED_SESSIONS)
{
LeaveCriticalSection(&s_discoveryLock);
continue;
}
Win64LANSession session; Win64LANSession session;
memset(&session, 0, sizeof(session)); memset(&session, 0, sizeof(session));
strncpy_s(session.hostIP, sizeof(session.hostIP), senderIP, _TRUNCATE); strncpy_s(session.hostIP, sizeof(session.hostIP), senderIP, _TRUNCATE);

View file

@ -12,7 +12,7 @@
#define WIN64_NET_DEFAULT_PORT 25565 #define WIN64_NET_DEFAULT_PORT 25565
#define WIN64_NET_MAX_CLIENTS 7 #define WIN64_NET_MAX_CLIENTS 7
#define WIN64_NET_RECV_BUFFER_SIZE 65536 #define WIN64_NET_RECV_BUFFER_SIZE 65536
#define WIN64_NET_MAX_PACKET_SIZE (4 * 1024 * 1024) #define WIN64_NET_MAX_PACKET_SIZE (3 * 1024 * 1024)
#define WIN64_LAN_DISCOVERY_PORT 25566 #define WIN64_LAN_DISCOVERY_PORT 25566
#define WIN64_LAN_BROADCAST_MAGIC 0x4D434C4E #define WIN64_LAN_BROADCAST_MAGIC 0x4D434C4E
@ -57,6 +57,7 @@ struct Win64RemoteConnection
BYTE smallId; BYTE smallId;
HANDLE recvThread; HANDLE recvThread;
volatile bool active; volatile bool active;
CRITICAL_SECTION sendLock;
}; };
class WinsockNetLayer class WinsockNetLayer
@ -86,6 +87,10 @@ public:
static void PushFreeSmallId(BYTE smallId); static void PushFreeSmallId(BYTE smallId);
static void CloseConnectionBySmallId(BYTE smallId); static void CloseConnectionBySmallId(BYTE smallId);
static bool PopPendingJoinSmallId(BYTE *outSmallId);
static bool IsSmallIdConnected(BYTE smallId);
static bool StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer); static bool StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer);
static void StopAdvertising(); static void StopAdvertising();
static void UpdateAdvertisePlayerCount(BYTE count); static void UpdateAdvertisePlayerCount(BYTE count);
@ -122,7 +127,7 @@ private:
static CRITICAL_SECTION s_sendLock; static CRITICAL_SECTION s_sendLock;
static CRITICAL_SECTION s_connectionsLock; static CRITICAL_SECTION s_connectionsLock;
static std::vector<Win64RemoteConnection> s_connections; static Win64RemoteConnection s_connections[WIN64_NET_MAX_CLIENTS + 1];
static SOCKET s_advertiseSock; static SOCKET s_advertiseSock;
static HANDLE s_advertiseThread; static HANDLE s_advertiseThread;
@ -140,6 +145,9 @@ private:
static CRITICAL_SECTION s_disconnectLock; static CRITICAL_SECTION s_disconnectLock;
static std::vector<BYTE> s_disconnectedSmallIds; static std::vector<BYTE> s_disconnectedSmallIds;
static CRITICAL_SECTION s_pendingJoinLock;
static std::vector<BYTE> s_pendingJoinSmallIds;
static CRITICAL_SECTION s_freeSmallIdLock; static CRITICAL_SECTION s_freeSmallIdLock;
static std::vector<BYTE> s_freeSmallIds; static std::vector<BYTE> s_freeSmallIds;
}; };

View file

@ -528,10 +528,10 @@ void Renderer::StateSetViewport(C4JRender::eViewportType viewportType)
case C4JRender::VIEWPORT_TYPE_FULLSCREEN: case C4JRender::VIEWPORT_TYPE_FULLSCREEN:
break; break;
case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
y = fullHeight * 0.5f;
height = fullHeight * 0.5f; height = fullHeight * 0.5f;
break; break;
case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM: case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
y = fullHeight * 0.5f;
height = fullHeight * 0.5f; height = fullHeight * 0.5f;
break; break;
case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT: case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:

View file

@ -140,8 +140,9 @@ DWORD CDLC::MountInstalledDLC(int iPad, DWORD dwDLC, int (*Func)(LPVOID, int, DW
this->m_uiCurrentMappedDLC = dwDLC; this->m_uiCurrentMappedDLC = dwDLC;
char *dlcdirPath = m_vInstalledDLCs[m_uiCurrentMappedDLC].szFileName; char *dlcdirPath = m_vInstalledDLCs[m_uiCurrentMappedDLC].szFileName;
m_vDLCDriveMappings.push_back(DriveMapping(dlcdirPath, m_szMountPath)); m_vDLCDriveMappings.push_back(DriveMapping(m_szMountPath, dlcdirPath));
dword94 = 0xFFFFFFFF;
m_iHasNewMountedDLCs = true; m_iHasNewMountedDLCs = true;
return 997; return 997;

View file

@ -155,6 +155,9 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
shared_ptr<ItemInstance> clickedEntity = nullptr; shared_ptr<ItemInstance> clickedEntity = nullptr;
shared_ptr<Inventory> inventory = player->inventory; shared_ptr<Inventory> inventory = player->inventory;
if (slotIndex != CLICKED_OUTSIDE && (slotIndex < 0 || slotIndex >= (int)slots->size()))
return nullptr;
if ((clickType == CLICK_PICKUP || clickType == CLICK_QUICK_MOVE) && (buttonNum == 0 || buttonNum == 1)) if ((clickType == CLICK_PICKUP || clickType == CLICK_QUICK_MOVE) && (buttonNum == 0 || buttonNum == 1))
{ {
if (slotIndex == CLICKED_OUTSIDE) if (slotIndex == CLICKED_OUTSIDE)
@ -403,12 +406,13 @@ bool AbstractContainerMenu::isPauseScreen()
void AbstractContainerMenu::setItem(unsigned int slot, shared_ptr<ItemInstance> item) void AbstractContainerMenu::setItem(unsigned int slot, shared_ptr<ItemInstance> item)
{ {
if (slot >= slots->size()) return;
getSlot(slot)->set(item); getSlot(slot)->set(item);
} }
void AbstractContainerMenu::setAll(ItemInstanceArray *items) void AbstractContainerMenu::setAll(ItemInstanceArray *items)
{ {
for (unsigned int i = 0; i < items->length; i++) for (unsigned int i = 0; i < items->length && i < slots->size(); i++)
{ {
getSlot(i)->set( (*items)[i] ); getSlot(i)->set( (*items)[i] );
} }

View file

@ -47,7 +47,7 @@ void AwardStatPacket::read(DataInputStream *dis) //throws IOException
// Read parameter blob. // Read parameter blob.
int length = dis->readInt(); int length = dis->readInt();
if(length > 0) if(length > 0 && length <= 65536)
{ {
m_paramData = byteArray(length); m_paramData = byteArray(length);
dis->readFully(m_paramData); dis->readFully(m_paramData);

View file

@ -97,6 +97,12 @@ void BlockRegionUpdatePacket::read(DataInputStream *dis) //throws IOException
levelIdx = ( size >> 30 ) & 3; levelIdx = ( size >> 30 ) & 3;
size &= 0x3fffffff; size &= 0x3fffffff;
const int MAX_COMPRESSED_CHUNK_SIZE = 5 * 1024 * 1024;
if(size < 0 || size > MAX_COMPRESSED_CHUNK_SIZE)
{
size = 0;
}
if(size == 0) if(size == 0)
{ {
buffer = byteArray(); buffer = byteArray();
@ -125,7 +131,10 @@ void BlockRegionUpdatePacket::read(DataInputStream *dis) //throws IOException
delete [] compressedBuffer.data; delete [] compressedBuffer.data;
assert(buffer.length == outputSize); if(buffer.length != outputSize)
{
app.DebugPrintf("BlockRegionUpdatePacket: decompressed size mismatch (expected %d, got %d)\n", buffer.length, outputSize);
}
} }
} }

View file

@ -10,8 +10,14 @@
//offset - the offset in the buffer of the first byte to read. //offset - the offset in the buffer of the first byte to read.
//length - the maximum number of bytes to read from the buffer. //length - the maximum number of bytes to read from the buffer.
ByteArrayInputStream::ByteArrayInputStream(byteArray buf, unsigned int offset, unsigned int length) ByteArrayInputStream::ByteArrayInputStream(byteArray buf, unsigned int offset, unsigned int length)
: pos( offset ), count( min( offset+length, buf.length ) ), mark( offset ) : pos( offset ), mark( offset )
{ {
if( offset > buf.length )
count = buf.length;
else if( length > buf.length - offset )
count = buf.length;
else
count = offset + length;
this->buf = buf; this->buf = buf;
} }

View file

@ -51,14 +51,23 @@ void ByteArrayOutputStream::write(byteArray b)
//len - the number of bytes to write. //len - the number of bytes to write.
void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int length) void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int length)
{ {
assert( b.length >= offset + length );
if (offset > b.length || length > b.length - offset)
return;
if (length > 0xFFFFFFFF - count)
return;
// If we will fill the buffer we need to make it bigger // If we will fill the buffer we need to make it bigger
if( count + length >= buf.length ) if( count + length >= buf.length )
buf.resize( max( count + length + 1, buf.length * 2 ) ); {
unsigned int newSize = (std::max)( count + length + 1, buf.length * 2 );
if( newSize <= buf.length )
return;
buf.resize( newSize );
}
XMemCpy( &buf[count], &b[offset], length ); XMemCpy( &buf[count], &b[offset], length );
//std::copy( b->data+offset, b->data+offset+length, buf->data + count ); // Or this instead?
count += length; count += length;
} }

View file

@ -19,7 +19,8 @@ public:
void load(DataInput *dis) void load(DataInput *dis)
{ {
int length = dis->readInt(); int length = dis->readInt();
if (length < 0 || length > 2 * 1024 * 1024) length = 0;
if ( data.data ) delete[] data.data; if ( data.data ) delete[] data.data;
data = byteArray(length); data = byteArray(length);
dis->readFully(data); dis->readFully(data);

View file

@ -32,7 +32,9 @@ void ComplexItemDataPacket::read(DataInputStream *dis) //throws IOException
itemType = dis->readShort(); itemType = dis->readShort();
itemId = dis->readShort(); itemId = dis->readShort();
data = charArray(dis->readShort() & 0xffff); int dataLength = dis->readShort() & 0xffff;
if(dataLength > 32767) dataLength = 0;
data = charArray(dataLength);
dis->readFully(data); dis->readFully(data);
} }

View file

@ -35,9 +35,12 @@ public:
{ {
tags.clear(); tags.clear();
Tag *tag; Tag *tag;
int tagCount = 0;
const int MAX_COMPOUND_TAGS = 10000;
while ((tag = Tag::readNamedTag(dis))->getId() != Tag::TAG_End) while ((tag = Tag::readNamedTag(dis))->getId() != Tag::TAG_End)
{ {
tags[tag->getName()] = tag; tags[tag->getName()] = tag;
if(++tagCount >= MAX_COMPOUND_TAGS) break;
} }
delete tag; delete tag;
} }

View file

@ -108,8 +108,8 @@ Connection::Connection(Socket *socket, const wstring& id, PacketListener *packet
const char *szId = wstringtofilename(id); const char *szId = wstringtofilename(id);
char readThreadName[256]; char readThreadName[256];
char writeThreadName[256]; char writeThreadName[256];
sprintf(readThreadName,"%s read\n",szId); sprintf_s(readThreadName, sizeof(readThreadName), "%.240s read\n", szId);
sprintf(writeThreadName,"%s write\n",szId); sprintf_s(writeThreadName, sizeof(writeThreadName), "%.240s write\n", szId);
readThread = new C4JThread(runRead, (void*)this, readThreadName, READ_STACK_SIZE); readThread = new C4JThread(runRead, (void*)this, readThreadName, READ_STACK_SIZE);
writeThread = new C4JThread(runWrite, this, writeThreadName, WRITE_STACK_SIZE); writeThread = new C4JThread(runWrite, this, writeThreadName, WRITE_STACK_SIZE);

View file

@ -32,6 +32,9 @@ void ContainerSetContentPacket::read(DataInputStream *dis) //throws IOException
{ {
containerId = dis->readByte(); containerId = dis->readByte();
int count = dis->readShort(); int count = dis->readShort();
if(count < 0 || count > 256) count = 0;
items = ItemInstanceArray(count); items = ItemInstanceArray(count);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {

View file

@ -35,7 +35,7 @@ void ContainerSetSlotPacket::read(DataInputStream *dis) //throws IOException
// 4J Stu - TU-1 hotfix // 4J Stu - TU-1 hotfix
// Fix for #13142 - Holding down the A button on the furnace ingredient slot causes the UI to display incorrect item counts // Fix for #13142 - Holding down the A button on the furnace ingredient slot causes the UI to display incorrect item counts
BYTE byteId = dis->readByte(); BYTE byteId = dis->readByte();
containerId = *(char *)&byteId; containerId = (char)(signed char)byteId;
slot = dis->readShort(); slot = dis->readShort();
item = readItem(dis); item = readItem(dis);
} }

View file

@ -43,7 +43,7 @@ void CustomPayloadPacket::read(DataInputStream *dis)
identifier = readUtf(dis, 20); identifier = readUtf(dis, 20);
length = dis->readShort(); length = dis->readShort();
if (length > 0 && length < Short::MAX_VALUE) if (length > 0 && length <= Short::MAX_VALUE)
{ {
if(data.data != NULL) if(data.data != NULL)
{ {

View file

@ -296,6 +296,10 @@ wstring DataInputStream::readUTF()
int b = stream->read(); int b = stream->read();
unsigned short UTFLength = (unsigned short) (((a & 0xff) << 8) | (b & 0xff)); unsigned short UTFLength = (unsigned short) (((a & 0xff) << 8) | (b & 0xff));
const unsigned short MAX_UTF_LENGTH = 32767;
if( UTFLength > MAX_UTF_LENGTH )
return outputString;
//// 4J Stu - I decided while writing DataOutputStream that we didn't need to bother using the UTF8 format //// 4J Stu - I decided while writing DataOutputStream that we didn't need to bother using the UTF8 format
//// used in the java libs, and just write in/out as wchar_t all the time //// used in the java libs, and just write in/out as wchar_t all the time

View file

@ -433,6 +433,29 @@ bool DirectoryLevelStorage::load(shared_ptr<Player> player)
{ {
bool newPlayer = true; bool newPlayer = true;
CompoundTag *tag = loadPlayerDataTag( player->getXuid() ); CompoundTag *tag = loadPlayerDataTag( player->getXuid() );
#ifdef _WINDOWS64
if (tag == NULL)
{
const PlayerUID WIN64_XUID_BASE = (PlayerUID)0xe000d45248242f2e;
for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++)
{
PlayerUID oldXuid = WIN64_XUID_BASE + i;
tag = loadPlayerDataTag(oldXuid);
if (tag != NULL)
{
ConsoleSavePath oldFile = ConsoleSavePath(playerDir.getName() + _toString(oldXuid) + L".dat");
if (m_saveFile->doesFileExist(oldFile))
{
m_saveFile->deleteFile(m_saveFile->createFile(oldFile));
}
app.DebugPrintf("Migrated player data from old XUID %llu to new XUID %llu\n", oldXuid, player->getXuid());
break;
}
}
}
#endif
if (tag != NULL) if (tag != NULL)
{ {
newPlayer = false; newPlayer = false;

View file

@ -56,6 +56,8 @@ void ExplodePacket::read(DataInputStream *dis) //throws IOException
r = dis->readFloat(); r = dis->readFloat();
int count = dis->readInt(); int count = dis->readInt();
if(count < 0 || count > 32768) count = 0;
int xp = (int)x; int xp = (int)x;
int yp = (int)y; int yp = (int)y;
int zp = (int)z; int zp = (int)z;

View file

@ -40,7 +40,7 @@ void GameCommandPacket::read(DataInputStream *dis)
command = (EGameCommand)dis->readInt(); command = (EGameCommand)dis->readInt();
length = dis->readShort(); length = dis->readShort();
if (length > 0 && length < Short::MAX_VALUE) if (length > 0 && length <= Short::MAX_VALUE)
{ {
if(data.data != NULL) if(data.data != NULL)
{ {

View file

@ -29,6 +29,7 @@ public:
void load(DataInput *dis) void load(DataInput *dis)
{ {
int length = dis->readInt(); int length = dis->readInt();
if (length < 0 || length > 65536) length = 0;
if ( data.data ) delete[] data.data; if ( data.data ) delete[] data.data;
data = intArray(length); data = intArray(length);

View file

@ -1174,7 +1174,6 @@ void LevelChunk::addEntity(shared_ptr<Entity> e)
int zc = Mth::floor(e->z / 16); int zc = Mth::floor(e->z / 16);
if (xc != this->x || zc != this->z) if (xc != this->x || zc != this->z)
{ {
app.DebugPrintf("Wrong location!");
// System.out.println("Wrong location! " + e); // System.out.println("Wrong location! " + e);
// Thread.dumpStack(); // Thread.dumpStack();
} }

View file

@ -28,11 +28,13 @@ public:
{ {
type = dis->readByte(); type = dis->readByte();
int size = dis->readInt(); int size = dis->readInt();
if (size < 0 || size > 10000) size = 0;
list.clear(); list.clear();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
Tag *tag = Tag::newTag(type, L""); Tag *tag = Tag::newTag(type, L"");
if (tag == NULL) break;
tag->load(dis); tag->load(dis);
list.push_back(tag); list.push_back(tag);
} }

View file

@ -760,7 +760,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;NDEBUG;_XBOX;_LIB;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_XBOX;_LIB;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -786,7 +786,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;NDEBUG;_XBOX;_LIB;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_XBOX;_LIB;%(PreprocessorDefinitions);PROFILE</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -871,7 +871,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -903,7 +903,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -935,7 +935,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -1051,7 +1051,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_LARGE_WORLDS;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -1074,7 +1074,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_LARGE_WORLDS;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -1097,7 +1097,7 @@
<BufferSecurityCheck>true</BufferSecurityCheck> <BufferSecurityCheck>true</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;USE_PIX;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;USE_PIX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -1125,7 +1125,7 @@
<BufferSecurityCheck>true</BufferSecurityCheck> <BufferSecurityCheck>true</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;USE_PIX;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;UNICODE;_UNICODE;__WRL_NO_DEFAULT_LIB__;WINAPI_FAMILY=WINAPI_FAMILY_TV_TITLE;WIN32_LEAN_AND_MEAN;_XM_AVX_INTRINSICS_;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_DURANGO;USE_PIX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling> <CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
@ -1375,7 +1375,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<BasicRuntimeChecks>Default</BasicRuntimeChecks> <BasicRuntimeChecks>Default</BasicRuntimeChecks>
<DisableSpecificWarnings>1700;613;1011</DisableSpecificWarnings> <DisableSpecificWarnings>1700;613;1011</DisableSpecificWarnings>
@ -1403,7 +1403,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_EXTENDED_ACHIEVEMENTS;_ITERATOR_DEBUG_LEVEL=0;_SECURE_SCL=0;_LIB;__PSVITA__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<BasicRuntimeChecks>Default</BasicRuntimeChecks> <BasicRuntimeChecks>Default</BasicRuntimeChecks>
<DisableSpecificWarnings>1700;613;1011</DisableSpecificWarnings> <DisableSpecificWarnings>1700;613;1011</DisableSpecificWarnings>
@ -1689,7 +1689,7 @@
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<CppExceptions>true</CppExceptions> <CppExceptions>true</CppExceptions>
<OptimizationLevel>Level2</OptimizationLevel> <OptimizationLevel>Level2</OptimizationLevel>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS</PreprocessorDefinitions>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage_Vita|ORBIS'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage_Vita|ORBIS'">
@ -1701,7 +1701,7 @@
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<CppExceptions>true</CppExceptions> <CppExceptions>true</CppExceptions>
<OptimizationLevel>Level2</OptimizationLevel> <OptimizationLevel>Level2</OptimizationLevel>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS</PreprocessorDefinitions>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage|ORBIS'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage|ORBIS'">
@ -1732,7 +1732,7 @@
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<RuntimeTypeInfo>true</RuntimeTypeInfo> <RuntimeTypeInfo>true</RuntimeTypeInfo>
<CppExceptions>true</CppExceptions> <CppExceptions>true</CppExceptions>
<PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED</PreprocessorDefinitions> <PreprocessorDefinitions>SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS</PreprocessorDefinitions>
<Warnings>WarningsOff</Warnings> <Warnings>WarningsOff</Warnings>
<OptimizationLevel>Levels</OptimizationLevel> <OptimizationLevel>Levels</OptimizationLevel>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
@ -3963,4 +3963,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View file

@ -287,17 +287,9 @@ __int64 Packet::getIndexedStatValue(unsigned int samplePos, unsigned int rendera
shared_ptr<Packet> Packet::getPacket(int id) shared_ptr<Packet> Packet::getPacket(int id)
{ {
// 4J - removed try/catch auto it = idToCreateMap.find(id);
// try if (it == idToCreateMap.end()) return nullptr;
// { return it->second();
return idToCreateMap[id]();
// }
// catch (exception e)
// {
// // TODO 4J JEV print stack trace, newInstance doesnt throw an exception in c++ yet.
// printf("Skipping packet with id %d" , id);
// return NULL;
// }
} }
void Packet::writeBytes(DataOutputStream *dataoutputstream, byteArray bytes) void Packet::writeBytes(DataOutputStream *dataoutputstream, byteArray bytes)
@ -358,14 +350,11 @@ shared_ptr<Packet> Packet::readPacket(DataInputStream *dis, bool isServer) // th
if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end())) if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end()))
{ {
//app.DebugPrintf("Bad packet id %d\n", id); return nullptr;
__debugbreak();
assert(false);
// throw new IOException(wstring(L"Bad packet id ") + _toString<int>(id));
} }
packet = getPacket(id); packet = getPacket(id);
if (packet == NULL) assert(false);//throw new IOException(wstring(L"Bad packet id ") + _toString<int>(id)); if (packet == NULL) return nullptr;
//app.DebugPrintf("%s reading packet %d\n", isServer ? "Server" : "Client", packet->getId()); //app.DebugPrintf("%s reading packet %d\n", isServer ? "Server" : "Client", packet->getId());
packet->read(dis); packet->read(dis);
@ -423,17 +412,9 @@ wstring Packet::readUtf(DataInputStream *dis, int maxLength) // throws IOExcepti
{ {
short stringLength = dis->readShort(); short stringLength = dis->readShort();
if (stringLength > maxLength) if (stringLength > maxLength || stringLength < 0)
{ {
wstringstream stream; return L"";
stream << L"Received string length longer than maximum allowed (" << stringLength << " > " << maxLength << ")";
assert(false);
// throw new IOException( stream.str() );
}
if (stringLength < 0)
{
assert(false);
// throw new IOException(L"Received string length is less than zero! Weird string!");
} }
wstring builder = L""; wstring builder = L"";
@ -534,7 +515,7 @@ shared_ptr<ItemInstance> Packet::readItem(DataInputStream *dis)
{ {
shared_ptr<ItemInstance> item = nullptr; shared_ptr<ItemInstance> item = nullptr;
int id = dis->readShort(); int id = dis->readShort();
if (id >= 0) if (id >= 0 && id < 32000) // validate against Item::ITEM_NUM_COUNT
{ {
int count = dis->readByte(); int count = dis->readByte();
int damage = dis->readShort(); int damage = dis->readShort();
@ -572,9 +553,16 @@ void Packet::writeItem(shared_ptr<ItemInstance> item, DataOutputStream *dos)
CompoundTag *Packet::readNbt(DataInputStream *dis) CompoundTag *Packet::readNbt(DataInputStream *dis)
{ {
int size = dis->readShort(); int size = dis->readShort();
if (size < 0) return NULL; if (size <= 0) return NULL;
const int MAX_NBT_SIZE = 32767;
if (size > MAX_NBT_SIZE) return NULL;
byteArray buff(size); byteArray buff(size);
dis->readFully(buff); if (!dis->readFully(buff))
{
delete [] buff.data;
return NULL;
}
CompoundTag *result = (CompoundTag *) NbtIo::decompress(buff); CompoundTag *result = (CompoundTag *) NbtIo::decompress(buff);
delete [] buff.data; delete [] buff.data;
return result; return result;

View file

@ -62,6 +62,7 @@ void PreLoginPacket::read(DataInputStream *dis) //throws IOException
m_friendsOnlyBits = dis->readByte(); m_friendsOnlyBits = dis->readByte();
m_ugcPlayersVersion = dis->readInt(); m_ugcPlayersVersion = dis->readInt();
m_dwPlayerCount = dis->readByte(); m_dwPlayerCount = dis->readByte();
if( m_dwPlayerCount > MINECRAFT_NET_MAX_PLAYERS ) m_dwPlayerCount = MINECRAFT_NET_MAX_PLAYERS;
if( m_dwPlayerCount > 0 ) if( m_dwPlayerCount > 0 )
{ {
m_playerXuids = new PlayerUID[m_dwPlayerCount]; m_playerXuids = new PlayerUID[m_dwPlayerCount];
@ -74,6 +75,7 @@ void PreLoginPacket::read(DataInputStream *dis) //throws IOException
{ {
m_szUniqueSaveName[i]=dis->readByte(); m_szUniqueSaveName[i]=dis->readByte();
} }
m_szUniqueSaveName[m_iSaveNameLen - 1] = 0;
m_serverSettings = dis->readInt(); m_serverSettings = dis->readInt();
m_hostIndex = dis->readByte(); m_hostIndex = dis->readByte();

View file

@ -21,7 +21,9 @@ RemoveEntitiesPacket::~RemoveEntitiesPacket()
void RemoveEntitiesPacket::read(DataInputStream *dis) //throws IOException void RemoveEntitiesPacket::read(DataInputStream *dis) //throws IOException
{ {
ids = intArray(dis->readByte()); int count = dis->readByte();
if(count < 0) count = 0;
ids = intArray(count);
for(unsigned int i = 0; i < ids.length; ++i) for(unsigned int i = 0; i < ids.length; ++i)
{ {
ids[i] = dis->readInt(); ids[i] = dis->readInt();

View file

@ -138,6 +138,11 @@ void Socket::pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHos
} }
EnterCriticalSection(&m_queueLockNetwork[queueIdx]); EnterCriticalSection(&m_queueLockNetwork[queueIdx]);
if(m_queueNetwork[queueIdx].size() + dwDataSize > 2 * 1024 * 1024)
{
LeaveCriticalSection(&m_queueLockNetwork[queueIdx]);
return;
}
for( unsigned int i = 0; i < dwDataSize; i++ ) for( unsigned int i = 0; i < dwDataSize; i++ )
{ {
m_queueNetwork[queueIdx].push(*pbData++); m_queueNetwork[queueIdx].push(*pbData++);

View file

@ -314,8 +314,10 @@ vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(Data
vector<shared_ptr<DataItem> > *result = NULL; vector<shared_ptr<DataItem> > *result = NULL;
int currentHeader = input->readByte(); int currentHeader = input->readByte();
int itemCount = 0;
const int MAX_ENTITY_DATA_ITEMS = 256;
while (currentHeader != EOF_MARKER) while (currentHeader != EOF_MARKER && itemCount < MAX_ENTITY_DATA_ITEMS)
{ {
if (result == NULL) if (result == NULL)
@ -363,6 +365,7 @@ vector<shared_ptr<SynchedEntityData::DataItem> > *SynchedEntityData::unpack(Data
break; break;
} }
result->push_back(item); result->push_back(item);
itemCount++;
currentHeader = input->readByte(); currentHeader = input->readByte();
} }

View file

@ -79,27 +79,44 @@ Tag *Tag::setName(const wstring& name)
Tag *Tag::readNamedTag(DataInput *dis) Tag *Tag::readNamedTag(DataInput *dis)
{ {
byte type = dis->readByte(); static __declspec(thread) int depth = 0;
if (type == 0) return new EndTag(); static __declspec(thread) int totalTagCount = 0;
// 4J Stu - readByte can return -1, so if it's that then also mark as the end tag if (depth == 0)
if(type == 255) totalTagCount = 0;
depth++;
if (depth > 256)
{ {
app.DebugPrintf("readNamedTag read a type of 255\n"); depth--;
#ifndef _CONTENT_PACKAGE
__debugbreak();
#endif
return new EndTag(); return new EndTag();
} }
wstring name = dis->readUTF();//new String(bytes, "UTF-8"); totalTagCount++;
const int MAX_TOTAL_TAGS = 32768;
if (totalTagCount > MAX_TOTAL_TAGS)
{
depth--;
return new EndTag();
}
byte type = dis->readByte();
if (type == 0) { depth--; return new EndTag(); }
if(type == 255)
{
depth--;
return new EndTag();
}
wstring name = dis->readUTF();
Tag *tag = newTag(type, name); Tag *tag = newTag(type, name);
// short length = dis.readShort(); if (tag == NULL) { depth--; return new EndTag(); }
// byte[] bytes = new byte[length];
// dis.readFully(bytes);
tag->load(dis); tag->load(dis);
depth--;
return tag; return tag;
} }

View file

@ -123,7 +123,17 @@ void TextureAndGeometryPacket::read(DataInputStream *dis) //throws IOException
{ {
textureName = dis->readUTF(); textureName = dis->readUTF();
dwSkinID = (DWORD)dis->readInt(); dwSkinID = (DWORD)dis->readInt();
dwTextureBytes = (DWORD)dis->readShort();
short rawTextureBytes = dis->readShort();
if(rawTextureBytes <= 0)
{
dwTextureBytes = 0;
}
else
{
dwTextureBytes = (DWORD)(unsigned short)rawTextureBytes;
if(dwTextureBytes > 65536) dwTextureBytes = 0;
}
if(dwTextureBytes>0) if(dwTextureBytes>0)
{ {
@ -136,7 +146,16 @@ void TextureAndGeometryPacket::read(DataInputStream *dis) //throws IOException
} }
uiAnimOverrideBitmask = dis->readInt(); uiAnimOverrideBitmask = dis->readInt();
dwBoxC = (DWORD)dis->readShort(); short rawBoxC = dis->readShort();
if(rawBoxC <= 0)
{
dwBoxC = 0;
}
else
{
dwBoxC = (DWORD)(unsigned short)rawBoxC;
if(dwBoxC > 256) dwBoxC = 0; // sane limit for skin boxes
}
if(dwBoxC>0) if(dwBoxC>0)
{ {

View file

@ -37,9 +37,19 @@ void TexturePacket::handle(PacketListener *listener)
void TexturePacket::read(DataInputStream *dis) //throws IOException void TexturePacket::read(DataInputStream *dis) //throws IOException
{ {
textureName = dis->readUTF(); textureName = dis->readUTF();
dwBytes = (DWORD)dis->readShort(); short rawBytes = dis->readShort();
if(rawBytes <= 0)
{
dwBytes = 0;
return;
}
dwBytes = (DWORD)(unsigned short)rawBytes;
if(dwBytes > 65536)
{
dwBytes = 0;
return;
}
if(dwBytes>0)
{ {
this->pbData= new BYTE [dwBytes]; this->pbData= new BYTE [dwBytes];

View file

@ -22,9 +22,9 @@ void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName )
#if ( defined _WINDOWS64 | defined _DURANGO ) #if ( defined _WINDOWS64 | defined _DURANGO )
__try __try
{ {
RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR *)&info ); RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR *)&info );
} }
__except( GetExceptionCode()==0x406D1388 ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER ) __except( EXCEPTION_EXECUTE_HANDLER )
{ {
} }
#endif #endif

View file

@ -42,7 +42,7 @@ void UpdateGameRuleProgressPacket::read(DataInputStream *dis) //throws IOExcepti
m_dataTag = dis->readInt(); m_dataTag = dis->readInt();
int dataLength = dis->readInt(); int dataLength = dis->readInt();
if(dataLength > 0) if(dataLength > 0 && dataLength <= 65536)
{ {
m_data = byteArray(dataLength); m_data = byteArray(dataLength);
dis->readFully(m_data); dis->readFully(m_data);

View file

@ -196,9 +196,20 @@ HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSiz
unsigned int rleSize = staticRleSize; unsigned int rleSize = staticRleSize;
unsigned char *dynamicRleBuf = NULL; unsigned char *dynamicRleBuf = NULL;
if(*pDestSize > rleSize)
unsigned int safeRleSize = max(rleSize, *pDestSize);
const unsigned int MAX_RLE_ALLOC = 16 * 1024 * 1024; // 16 MB
if(safeRleSize > MAX_RLE_ALLOC)
{ {
rleSize = *pDestSize; LeaveCriticalSection(&rleDecompressLock);
*pDestSize = 0;
return E_FAIL;
}
if(safeRleSize > staticRleSize)
{
rleSize = safeRleSize;
dynamicRleBuf = new unsigned char[rleSize]; dynamicRleBuf = new unsigned char[rleSize];
Decompress(dynamicRleBuf, &rleSize, pSource, SrcSize); Decompress(dynamicRleBuf, &rleSize, pSource, SrcSize);
pucIn = (unsigned char *)dynamicRleBuf; pucIn = (unsigned char *)dynamicRleBuf;
@ -212,16 +223,19 @@ HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSiz
//unsigned char *pucIn = (unsigned char *)rleDecompressBuf; //unsigned char *pucIn = (unsigned char *)rleDecompressBuf;
unsigned char *pucEnd = pucIn + rleSize; unsigned char *pucEnd = pucIn + rleSize;
unsigned char *pucOut = (unsigned char *)pDestination; unsigned char *pucOut = (unsigned char *)pDestination;
unsigned char *pucOutEnd = pucOut + *pDestSize;
while( pucIn != pucEnd ) while( pucIn != pucEnd )
{ {
unsigned char thisOne = *pucIn++; unsigned char thisOne = *pucIn++;
if( thisOne == 255 ) if( thisOne == 255 )
{ {
if( pucIn >= pucEnd ) break;
unsigned int count = *pucIn++; unsigned int count = *pucIn++;
if( count < 3 ) if( count < 3 )
{ {
count++; count++;
if( pucOut + count > pucOutEnd ) { pucOut = pucOutEnd; break; }
for( unsigned int i = 0; i < count; i++ ) for( unsigned int i = 0; i < count; i++ )
{ {
*pucOut++ = 255; *pucOut++ = 255;
@ -230,7 +244,9 @@ HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSiz
else else
{ {
count++; count++;
if( pucIn >= pucEnd ) break;
unsigned char data = *pucIn++; unsigned char data = *pucIn++;
if( pucOut + count > pucOutEnd ) { pucOut = pucOutEnd; break; }
for( unsigned int i = 0; i < count; i++ ) for( unsigned int i = 0; i < count; i++ )
{ {
*pucOut++ = data; *pucOut++ = data;
@ -239,6 +255,7 @@ HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSiz
} }
else else
{ {
if( pucOut >= pucOutEnd ) break;
*pucOut++ = thisOne; *pucOut++ = thisOne;
} }
} }
@ -260,16 +277,19 @@ HRESULT Compression::DecompressRLE(void *pDestination, unsigned int *pDestSize,
unsigned char *pucIn = (unsigned char *)pSource; unsigned char *pucIn = (unsigned char *)pSource;
unsigned char *pucEnd = pucIn + SrcSize; unsigned char *pucEnd = pucIn + SrcSize;
unsigned char *pucOut = (unsigned char *)pDestination; unsigned char *pucOut = (unsigned char *)pDestination;
unsigned char *pucOutEnd = pucOut + *pDestSize;
while( pucIn != pucEnd ) while( pucIn != pucEnd )
{ {
unsigned char thisOne = *pucIn++; unsigned char thisOne = *pucIn++;
if( thisOne == 255 ) if( thisOne == 255 )
{ {
if( pucIn >= pucEnd ) break;
unsigned int count = *pucIn++; unsigned int count = *pucIn++;
if( count < 3 ) if( count < 3 )
{ {
count++; count++;
if( pucOut + count > pucOutEnd ) { pucOut = pucOutEnd; break; }
for( unsigned int i = 0; i < count; i++ ) for( unsigned int i = 0; i < count; i++ )
{ {
*pucOut++ = 255; *pucOut++ = 255;
@ -278,7 +298,9 @@ HRESULT Compression::DecompressRLE(void *pDestination, unsigned int *pDestSize,
else else
{ {
count++; count++;
if( pucIn >= pucEnd ) break;
unsigned char data = *pucIn++; unsigned char data = *pucIn++;
if( pucOut + count > pucOutEnd ) { pucOut = pucOutEnd; break; }
for( unsigned int i = 0; i < count; i++ ) for( unsigned int i = 0; i < count; i++ )
{ {
*pucOut++ = data; *pucOut++ = data;
@ -287,6 +309,7 @@ HRESULT Compression::DecompressRLE(void *pDestination, unsigned int *pDestSize,
} }
else else
{ {
if( pucOut >= pucOutEnd ) break;
*pucOut++ = thisOne; *pucOut++ = thisOne;
} }
} }

View file

@ -233,6 +233,8 @@ private:
}; };
void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal); void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal);
PlayerUID Win64_UsernameToXuid(const char* username);
PlayerUID Win64_UsernameToXuid(const wchar_t* username);
const int QNET_GETSENDQUEUESIZE_SECONDARY_TYPE = 0; const int QNET_GETSENDQUEUESIZE_SECONDARY_TYPE = 0;
const int QNET_GETSENDQUEUESIZE_MESSAGES = 0; const int QNET_GETSENDQUEUESIZE_MESSAGES = 0;