Commit graph

11721 commits

Author SHA1 Message Date
Robert Müller ca31b495a9 Rename dump_binds command to binds, fix typo in description 2022-08-11 09:48:34 +02:00
Dennis Felsing d003cc6ee2 Use current backlog page instead of old (fixes #5719)
Better fix by Robyt3
2022-08-10 17:27:24 +02:00
Robert Müller a8e3ac1184 Minor refactoring: use int64_t instead of long long 2022-08-09 18:48:06 +02:00
Robert Müller 1e10cd3c7d Optimize conditional expression 2022-08-09 18:48:05 +02:00
Robert Müller 62445ac006 Remove unused HermiteBasis1 function 2022-08-09 18:48:05 +02:00
Robert Müller 05af632524 Rename variables v to Value 2022-08-09 18:48:05 +02:00
Robert Müller 1e6fd63204 Rename variables id to KeyID 2022-08-09 18:48:04 +02:00
bors[bot] 57849a128c
Merge #5717
5717: Check fully transparent quads with negative alpha r=def- a=Jupeyy

fixes #5716

Co-authored-by: Jupeyy <jupjopjap@gmail.com>
2022-08-09 15:49:32 +00:00
Jupeyy bc865ab087
Check transparency even for negative alpha 2022-08-09 17:44:09 +02:00
bors[bot] f8fca99e62
Merge #5642
5642: Option to remove weak hook & bounce r=def- a=Jupeyy

Fixes #5641 
server side only

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
2022-08-09 13:59:21 +00:00
bors[bot] dbe6d8cb29
Merge #5715
5715: Use djb2 for snapshot item hashlist r=def- a=Robyt3

The previous hash function was heavily biased towards the hash buckets 64-79, making those buckets overflow faster, which results in snapshot CRC errors and lags.

Using the djb2 hash yields an almost even distribution over the entire range of values.

Source for djb2: http://www.cse.yorku.ca/~oz/hash.html
(we incidentally use the same implementation for `str_quickhash`)

Sample which compares the usage of hash buckets in the test map from #5454 with the old and new hash function: [SnapshotHash.csv](https://github.com/ddnet/ddnet/files/9285148/SnapshotHash.csv) (this table also differentiates between the source and target of the snapshot delta)

Closes #4379.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-08-08 22:38:22 +00:00
Robert Müller 243ab7c2f0 Use djb2 for snapshot item hashlist
The previous hash function was heavily biased towards the hash buckets 64-79, making those buckets overflow faster, which results in snapshot CRC errors and lags.

Using the djb2 hash yields an almost even distribution over the entire range of values.

http://www.cse.yorku.ca/~oz/hash.html
2022-08-08 23:21:45 +02:00
Robert Müller 573aedc323 Extract magic constant 64 into HASHLIST_BUCKET_SIZE 2022-08-08 22:34:47 +02:00
Robert Müller b99b861e1c Extract common expression into CalcHashID function 2022-08-08 22:30:14 +02:00
Dennis Felsing 614a5b35bc Easter egg 2022-08-08 16:37:17 +02:00
Dennis Felsing 526861f924 Update language files, remove half-translated graphics warning
Thanks to cheeser0613 for report
2022-08-08 16:10:48 +02:00
bors[bot] aeca43fbdb
Merge #5706
5706: Fix shift-leftclick-drag with empty selection to delete (fixes #5705) r=C0D3D3V a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-08-06 10:54:33 +00:00
Dennis Felsing a41f1c1def Fix shift-leftclick-drag with empty selection to delete (fixes #5705) 2022-08-06 02:09:15 +02:00
Robert Müller b1e4d60fae Fix buffer-overflow in editor on shift-clicking brush
1. Open any map, including an empty one.
2. Select a brush, e.g. size 2x2.
3. Shift click to repeat the brush over a larger area, e.g. 10x10.
4. This causes a buffer-overflow / crash with ASAN:

```
=================================================================
==4826==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6060000f5040 at pc 0x55db7d0aa743 bp 0x7fffe4e191f0 sp 0x7fffe4e191e0
READ of size 4 at 0x6060000f5040 thread T0
    0 0x55db7d0aa742 in CLayerTiles::GetTile(int, int) src/game/editor/layer_tiles.cpp:50
    1 0x55db7d0d23e1 in CLayerTiles::FillSelection(bool, CLayer*, CUIRect) src/game/editor/layer_tiles.cpp:437
    2 0x55db7cf196e9 in CEditor::DoMapEditor(CUIRect) src/game/editor/editor.cpp:2641
    3 0x55db7cfa7755 in CEditor::Render() src/game/editor/editor.cpp:5747
    4 0x55db7cfd2a56 in CEditor::OnRender() src/game/editor/editor.cpp:6437
    5 0x55db7c23e02d in CClient::Run() src/engine/client/client.cpp:3374
    6 0x55db7c2a9f7b in main src/engine/client/client.cpp:4762

0x6060000f5040 is located 0 bytes to the right of 64-byte region [0x6060000f5000,0x6060000f5040)
allocated by thread T0 here:
    0 0x7f9b21db5787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
    1 0x55db7d0a9a86 in CLayerTiles::CLayerTiles(int, int) src/game/editor/layer_tiles.cpp:39
    2 0x55db7d0cf0ed in CLayerTiles::BrushGrab(CLayerGroup*, CUIRect) src/game/editor/layer_tiles.cpp:387
    3 0x55db7cf18191 in CEditor::DoMapEditor(CUIRect) src/game/editor/editor.cpp:2612
    4 0x55db7cfa7755 in CEditor::Render() src/game/editor/editor.cpp:5747
    5 0x55db7cfd2a56 in CEditor::OnRender() src/game/editor/editor.cpp:6437
    6 0x55db7c23e02d in CClient::Run() src/engine/client/client.cpp:3374

SUMMARY: AddressSanitizer: heap-buffer-overflow src/game/editor/layer_tiles.cpp:50 in CLayerTiles::GetTile(int, int)
Shadow bytes around the buggy address:
  0x0c0c800169b0: 00 00 00 fa fa fa fa fa 00 00 00 00 00 00 00 fa
  0x0c0c800169c0: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
  0x0c0c800169d0: fd fd fd fd fd fd fd fa fa fa fa fa fd fd fd fd
  0x0c0c800169e0: fd fd fd fd fa fa fa fa fd fd fd fd fd fd fd fa
  0x0c0c800169f0: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
=>0x0c0c80016a00: 00 00 00 00 00 00 00 00[fa]fa fa fa fd fd fd fd
  0x0c0c80016a10: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa
  0x0c0c80016a20: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
  0x0c0c80016a30: fd fd fd fd fd fd fd fa fa fa fa fa fd fd fd fd
  0x0c0c80016a40: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fa
  0x0c0c80016a50: fa fa fa fa fd fd fd fd fd fd fd fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==4826==ABORTING
```
2022-08-04 23:39:40 +02:00
Robert Müller c696d93e41 Add documentation for IServer::GetClientVersion 2022-08-03 23:28:51 +02:00
bors[bot] b4914d5d27
Merge #5692
5692: Refactor `GetClientVersion`, remove many `version.h` includes, fix potential use of undefined value r=def- a=Robyt3

Some refactoring to reduce duplicate code and to remove includes.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-08-01 21:21:18 +00:00
Robert Müller ee339ebe30 Minor refactoring of GetClientInfo and SetClientDDNetVersion 2022-07-31 23:37:56 +02:00
Robert Müller 24b30434da Handle CServer::GetClientInfo return to fix use of undefined value
```
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:790:2: error: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn,-warnings-as-errors]
        return Info.m_DDNetVersion;
        ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:785:5: note: Assuming 'ClientID' is not equal to SERVER_DEMO_CLIENT
        if(ClientID == SERVER_DEMO_CLIENT)
           ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:785:2: note: Taking false branch
        if(ClientID == SERVER_DEMO_CLIENT)
        ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:789:2: note: Calling 'CServer::GetClientInfo'
        GetClientInfo(ClientID, &Info);
        ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:646:13: note: Assuming 'ClientID' is >= 0
        dbg_assert(ClientID >= 0 && ClientID < MAX_CLIENTS, "client_id is not valid");
                   ^
/home/runner/work/ddnet/ddnet/src/base/tl/../system.h:58:38: note: expanded from macro 'dbg_assert'
#define dbg_assert(test, msg) assert(test)
                                     ^
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:646:13: note: Left side of '&&' is true
        dbg_assert(ClientID >= 0 && ClientID < MAX_CLIENTS, "client_id is not valid");
                   ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:646:30: note: Assuming 'ClientID' is < MAX_CLIENTS
        dbg_assert(ClientID >= 0 && ClientID < MAX_CLIENTS, "client_id is not valid");
                                    ^
/home/runner/work/ddnet/ddnet/src/base/tl/../system.h:58:38: note: expanded from macro 'dbg_assert'
#define dbg_assert(test, msg) assert(test)
                                     ^
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:646:2: note: '?' condition is true
        dbg_assert(ClientID >= 0 && ClientID < MAX_CLIENTS, "client_id is not valid");
        ^
/home/runner/work/ddnet/ddnet/src/base/tl/../system.h:58:31: note: expanded from macro 'dbg_assert'
#define dbg_assert(test, msg) assert(test)
                              ^
/usr/include/assert.h:93:7: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
      ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:647:13: note: 'pInfo' is not equal to null
        dbg_assert(pInfo != 0, "info can not be null");
                   ^
/home/runner/work/ddnet/ddnet/src/base/tl/../system.h:58:38: note: expanded from macro 'dbg_assert'
#define dbg_assert(test, msg) assert(test)
                                     ^
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:647:2: note: '?' condition is true
        dbg_assert(pInfo != 0, "info can not be null");
        ^
/home/runner/work/ddnet/ddnet/src/base/tl/../system.h:58:31: note: expanded from macro 'dbg_assert'
#define dbg_assert(test, msg) assert(test)
                              ^
/usr/include/assert.h:93:7: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
      ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:649:5: note: Assuming field 'm_State' is not equal to STATE_INGAME
        if(m_aClients[ClientID].m_State == CClient::STATE_INGAME)
           ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:649:2: note: Taking false branch
        if(m_aClients[ClientID].m_State == CClient::STATE_INGAME)
        ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:667:2: note: Returning without writing to 'pInfo->m_DDNetVersion'
        return 0;
        ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:789:2: note: Returning from 'CServer::GetClientInfo'
        GetClientInfo(ClientID, &Info);
        ^
/home/runner/work/ddnet/ddnet/src/engine/server/server.cpp:790:2: note: Undefined or garbage value returned to caller
        return Info.m_DDNetVersion;
        ^
```
2022-07-31 23:37:28 +02:00
Robert Müller 9a012312b8 Move and extend GetClientVersion to remove many version.h includes
The `CServer::GetClientVersion` method needs the `version.h` include, so it's moved from the header to the source file, so the include can be removed from the header.

The `GetClientVersion` method is often called with the same `Client != SERVER_DEMO_CLIENT ? GetClientVersion(Client) : CLIENT_VERSIONNR` expression, which also needs the `version.h` include. This expression is moved inside the method, so the include can be removed from all the server entities' and player code.

The `CGameContext::GetClientVersion` method is made a delegate to reduce duplicate code.

The includes of the server entities are also organized further.
2022-07-31 23:21:10 +02:00
bors[bot] 1110d0e40e
Merge #5686
5686: Fix editor image delete r=def- a=Jupeyy

fixes #5675

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
2022-07-31 21:11:15 +00:00
Chairn c651936f38 Use copy assignment rather than copy variable one by one 2022-07-31 22:43:43 +02:00
bors[bot] 730c54a603
Merge #5678
5678: Reset selected quads when switching layers (fixes #5673) r=Jupeyy a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
2022-07-31 20:03:31 +00:00
Jupeyy 982139922c Fix editor image delete 2022-07-31 21:39:18 +02:00
Robert Müller 1d6dca8c24 Fix accesses to vector with index -1 by adding static button IDs 2022-07-31 13:13:53 +02:00
Robert Müller 344e50f76f Remove dead code 2022-07-31 13:10:03 +02:00
def 76e3db9725 Reset selected quads when switching layers (fixes #5673) 2022-07-31 09:45:06 +02:00
def b33cbdde0a Remove unused backend_opengles.h 2022-07-31 09:44:50 +02:00
def fc5cfb6f6c Remove CFlag dead code (fixes #5677) 2022-07-31 09:44:50 +02:00
def 734790a4aa Fix deprecation warning in ffmpeg 5.1 (fixes #5681) 2022-07-31 00:58:15 +02:00
Robert Müller 7f1a7795ee Fix tab and F10 keys working inconsistently in editor
By moving the calls to `KeyPress` from `CEditor::OnUpdate` to `OnRender`.
2022-07-30 13:31:00 +02:00
Dennis Felsing d520fe6177 Fix rotating plasma by Robyt3 (fixes #5666) 2022-07-28 15:42:11 +02:00
bors[bot] 9a3f526cb6
Merge #5614
5614: Fix clang-tidy 14 mingw issues (fixes #5612) r=heinrich5991 a=def-

Strangely I didn't get all of the errors.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
2022-07-27 10:45:54 +00:00
Dennis Felsing 9d6ccbe838 Version 16.2.2 2022-07-27 12:22:43 +02:00
def c94de9b764 Further clang-tidy 14 issues (fixes #5612) 2022-07-27 09:07:47 +02:00
def 1944bc7052 Ignore Stack address escape clang-tidy warnings
/media/ddnet/src/engine/server.h:135:3: error: Address of stack memory associated with local variable 'aBuf' is still referred to by the stack variable 'tmp' upon returning to the caller.  This will be a dangling reference [clang-analyzer-core.StackAddressEscape,-warnings-as-errors]
                return SendPackMsgOne(pMsg, Flags, ClientID);
                ^
/media/ddnet/src/game/server/gamecontext.cpp:4084:5: note: Assuming the condition is false
        if(pFilter[0])
           ^~~~~~~~~~
/media/ddnet/src/game/server/gamecontext.cpp:4084:2: note: Taking false branch
        if(pFilter[0])
        ^
/media/ddnet/src/game/server/gamecontext.cpp:4088:2: note: Calling 'CGameContext::SendChatTarget'
        SendChatTarget(ClientID, aBuf);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/ddnet/src/game/server/gamecontext.cpp:401:5: note: Assuming field 'm_SvDemoChat' is not equal to 0
        if(g_Config.m_SvDemoChat)
           ^~~~~~~~~~~~~~~~~~~~~
/media/ddnet/src/game/server/gamecontext.cpp:401:2: note: Taking true branch
        if(g_Config.m_SvDemoChat)
        ^
/media/ddnet/src/game/server/gamecontext.cpp:402:3: note: Calling 'IServer::SendPackMsg'
                Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NOSEND, -1);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:71:3: note: Taking true branch
                if(ClientID == -1)
                ^
/media/ddnet/src/engine/server.h:73:19: note: Assuming the condition is true
                        for(int i = 0; i < MaxClients(); i++)
                                       ^~~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:73:4: note: Loop condition is true.  Entering loop body
                        for(int i = 0; i < MaxClients(); i++)
                        ^
/media/ddnet/src/engine/server.h:74:8: note: Assuming the condition is true
                                if(ClientIngame(i))
                                   ^~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:74:5: note: Taking true branch
                                if(ClientIngame(i))
                                ^
/media/ddnet/src/engine/server.h:77:15: note: Calling 'IServer::SendPackMsgTranslate'
                                        Result = SendPackMsgTranslate(&tmp, Flags, i);
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:118:6: note: Assuming field 'm_ClientID' is >= 0
                if(pMsg->m_ClientID >= 0 && !Translate(pMsg->m_ClientID, ClientID))
                   ^~~~~~~~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:118:6: note: Left side of '&&' is true
/media/ddnet/src/engine/server.h:118:31: note: Assuming the condition is true
                if(pMsg->m_ClientID >= 0 && !Translate(pMsg->m_ClientID, ClientID))
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:118:3: note: Taking true branch
                if(pMsg->m_ClientID >= 0 && !Translate(pMsg->m_ClientID, ClientID))
                ^
/media/ddnet/src/engine/server.h:125:6: note: Assuming the condition is false
                if(IsSixup(ClientID))
                   ^~~~~~~~~~~~~~~~~
/media/ddnet/src/engine/server.h:125:3: note: Taking false branch
                if(IsSixup(ClientID))
                ^
/media/ddnet/src/engine/server.h:135:3: note: Address of stack memory associated with local variable 'aBuf' is still referred to by the stack variable 'tmp' upon returning to the caller.  This will be a dangling reference
                return SendPackMsgOne(pMsg, Flags, ClientID);
                ^
2022-07-27 09:07:20 +02:00
def 6fc2296a6e Ignore openssl deprecation warning for now (fixes #5597) 2022-07-27 09:06:57 +02:00
bors[bot] 53e9fd3599
Merge #5627
5627: Fix shift + left click in editor (fixes #5626) r=heinrich5991 a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-07-26 19:11:24 +00:00
bors[bot] e8667b6075
Merge #5658
5658: Fix game freezing up on duplicate snapshot r=def- a=Fireball-Teeworlds

If a duplicate snapshot is received (for the same tick), we add both to the SnapshotStorage and end up with the same snapshot as both Cur and Prev. This results in GameInfraTick returning "inf" and results in "NaN" downstream in a few places, getting the CollLine logic stuck.

Some debug info (tcpdump, gdb, perf): https://gist.github.com/Fireball-Teeworlds/ad0016d2551a2e4d4cb5691023493856

Apparently this doesn't really happen in the wild, unless you have a buggy network stack. In which case it happens frequently enough to pinpoint the issue :D

 (fixes #5657)

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [X] Considered possible null pointers and out of bounds array indexing
- [X] Changed no physics that affect existing maps
- [X] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Fireball <fireball.teeworlds@gmail.com>
2022-07-26 13:46:40 +00:00
Fireball 9689301410 Fix game freezing up on duplicate snapshot
If a duplicate snapshot is received (for the same tick), we add both to the SnapshotStorage and end up with the same snapshot as both Cur and Prev. This results in GameInfraTick returning "inf" and results in "NaN" downstream in a few places, getting the CollLine logic stuck.

Apparently this doesn't really happen in the wild, unless you have a buggy network stack. In which case it happens frequently enough to pinpoint the issue :D
2022-07-24 21:57:05 +01:00
Robert Müller 1398936f54 Minor refactoring of CDemoPlayer::DoTick:
- Decrease variable scopes
- Use `bool` instead of `int`
2022-07-24 19:01:45 +02:00
Robert Müller 4c397e479a Refactor CSnapshotBuilder::Finish using TotalSize and OffsetSize 2022-07-24 18:04:48 +02:00
Robert Müller 3863d41623 Validate snapshot size and member variables and demo snapshots
Add `CSnapshot::IsValid` to check if a snapshot unpacked from a snapshot delta or demo is valid:
- ensure number of items and data size are not negative
- ensure that the actual size of the snapshot matches the size derived from its member variables
- ensure item offsets are within the valid range
- ensure item sizes are not negative

Add `CSnapshot::TotalSize` and `CSnapshot::OffsetSize` utility functions.

Minor improvements to related error messages.

Fixes buffer overflow:

```
==47744==ERROR: AddressSanitizer: global-buffer-overflow on address 0x558618e3767f at pc 0x558614b9bdfb bp 0x7ffe58a32cd0 sp 0x7ffe58a32cc0
READ of size 4 at 0x558618e3767f thread T0
    0x558614b9bdfa in CSnapshotItem::Type() const src/engine/shared/snapshot.h:16
    0x558615c3c911 in CSnapshot::GetItemType(int) const src/engine/shared/snapshot.cpp:29
    0x558614aebaba in CClient::UnpackAndValidateSnapshot(CSnapshot*, CSnapshot*) src/engine/client/client.cpp:2264
    0x558614af87cb in CClient::OnDemoPlayerSnapshot(void*, int) src/engine/client/client.cpp:2598
    0x558615b9db1a in CDemoPlayer::DoTick() src/engine/shared/demo.cpp:659
    0x558615babd3f in CDemoPlayer::Update(bool) src/engine/shared/demo.cpp:1007
    0x558614afb08b in CClient::Update() src/engine/client/client.cpp:2686
    0x558614b1d9eb in CClient::Run() src/engine/client/client.cpp:3296
    0x558614b8e64f in main src/engine/client/client.cpp:4761
```

And fixes a buffer overflow that manifests itself as an internal ASan error:

```
=================================================================
==4755==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/asan/asan_descriptions.cc:79 "((0 && "Address is not in memory and not in shadow?")) != (0)" (0x0, 0x0)
    0x7f0bf5f368be in AsanCheckFailed ../../../../src/libsanitizer/asan/asan_rtl.cc:72
    0x7f0bf5f54eee in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cc:77
    0x7f0bf5e4cb6f in GetShadowKind ../../../../src/libsanitizer/asan/asan_descriptions.cc:79
    0x7f0bf5e4cb6f in __asan::GetShadowAddressInformation(unsigned long, __asan::ShadowAddressDescription*) ../../../../src/libsanitizer/asan/asan_descriptions.cc:95
    0x7f0bf5e4cb6f in __asan::GetShadowAddressInformation(unsigned long, __asan::ShadowAddressDescription*) ../../../../src/libsanitizer/asan/asan_descriptions.cc:92
    0x7f0bf5e4e386 in __asan::AddressDescription::AddressDescription(unsigned long, unsigned long, bool) ../../../../src/libsanitizer/asan/asan_descriptions.cc:440
    0x7f0bf5e50e94 in __asan::ErrorGeneric::ErrorGeneric(unsigned int, unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long) ../../../../src/libsanitizer/asan/asan_errors.cc:380
    0x7f0bf5f35f4d in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ../../../../src/libsanitizer/asan/asan_report.cc:460
    0x7f0bf5e86f5e in __interceptor_memset ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:762
    0x558234873f1d in mem_zero src/base/system.cpp:213
    0x55823481fc27 in CSnapshotBuilder::NewItem(int, int, int) src/engine/shared/snapshot.cpp:675
    0x55823481be65 in CSnapshotDelta::UnpackDelta(CSnapshot*, CSnapshot*, void const*, int) src/engine/shared/snapshot.cpp:380
    0x558234776641 in CDemoPlayer::DoTick() src/engine/shared/demo.cpp:631
    0x5582347861a9 in CDemoPlayer::Update(bool) src/engine/shared/demo.cpp:1007
    0x5582336d4c7d in CClient::Update() src/engine/client/client.cpp:2695
    0x5582336f75dd in CClient::Run() src/engine/client/client.cpp:3305
    0x558233768241 in main src/engine/client/client.cpp:4770
```
2022-07-24 18:00:39 +02:00
Robert Müller 1b32e47173 Fix shift with negative exponent in TeamMask
```
src/game/server/teams.cpp:484:35: runtime error: shift exponent -1 is negative
    0x55d065b241c4 in CGameTeams::TeamMask(int, int, int) src/game/server/teams.cpp:484
    0x55d0657f92ed in CCharacter::TickDefered() src/game/server/entities/character.cpp:821
    0x55d065a5d04c in CGameWorld::Tick() src/game/server/gameworld.cpp:283
    0x55d0659327e6 in CGameContext::OnTick() src/game/server/gamecontext.cpp:852
    0x55d0656e6a88 in CServer::Run() src/engine/server/server.cpp:2807
    0x55d0657164f1 in main src/engine/server/server.cpp:3904
```
2022-07-22 16:42:56 +02:00
Jupeyy 88c4b69301 Add an option to remove weak hook & bounce 2022-07-21 17:04:16 +02:00
Robert Müller 95636da6d9 Fix out of bounds access with highlighted messages in server demos
```
src/game/client/components/chat.cpp:795:89: runtime error: index -1 out of bounds for type 'CClientData [64]'
    #0 0x55c133fd047a in CChat::AddLine(int, int, char const*) src/game/client/components/chat.cpp:795
    #1 0x55c133fc80b5 in CChat::OnMessage(int, void*) src/game/client/components/chat.cpp:570
    #2 0x55c134677688 in CGameClient::OnMessage(int, CUnpacker*, int, bool) src/game/client/gameclient.cpp:770
    #3 0x55c133c282d2 in CClient::OnDemoPlayerMessage(void*, int) src/engine/client/client.cpp:2627
    #4 0x55c134ccdcba in CDemoPlayer::DoTick() src/engine/shared/demo.cpp:679
    #5 0x55c134cdac81 in CDemoPlayer::Update(bool) src/engine/shared/demo.cpp:1007
    #6 0x55c133c2a08b in CClient::Update() src/engine/client/client.cpp:2686
    #7 0x55c133c4c9eb in CClient::Run() src/engine/client/client.cpp:3296
    #8 0x55c133cbd64f in main src/engine/client/client.cpp:4761
```
2022-07-21 15:32:11 +02:00