Validate instruction addresses and memory bounds in the emulator

オープン 初心者向け
#7 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp

調査の方向性

issueで特定された命令デコードループがある emulator/main.c から始めてください。メモリ読み取りの前に、BASE、命令値、計算されたアドレスがどのように使われるかを追い、その後、エミュレーターの既存のビルドまたは実行手順を確認してください。不正なベース、アドレス、命令が説明的なエラーとともに安全に停止し、有効なプログラムは引き続き動作すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug copilot

Summary

The emulator derives memory addresses from instruction values without validating them, which can read beyond the allocated memory and crash or corrupt state.

Problem

The code computes address = memory[i] % BASE and reads memory[address] for every instruction. If the program or base value is malformed, address may be outside the bounds of the memory array. Similarly, the instruction stream itself is not validated before decoding.

Expected behavior

  • Check BASE and address ranges before reading memory.
  • Reject instructions that are invalid for the current architecture.
  • Stop safely with a descriptive error on malformed programs.

Relevant code

  • emulator/main.c in the for loop that decodes instructions and accesses memory.

Suggested fix

Add range checks before each memory read and each address calculation. Reject BASE <= 0 and guard memory accesses with 0 <= address && address < MEMORY_SIZE before dereferencing them. Report invalid instructions instead of falling through to undefined behavior.

主要言語
C++
スター
0
フォーク
0
平均マージ
1分
マージ済み PR(30日)
4

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DavidSkillman/LittleManCompiler のほかの issue

DavidSkillman/LittleManCompiler の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。